Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1327] setRequestHeader -> "If-Modified-Since"

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2017-06-05T20:15:44.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, base64encode, defect, if-modified-since, setrequestheader
Reportermarco.schierhorn (at gmail)
AssigneeIngo Muschenetz
Created2011-04-15T02:49:29.000+0000
Updated2017-06-05T20:15:44.000+0000

Description

I cant use setRequestHeader with "If-Modified-Since" to get back at 304 Status.
I want to use this for storing images and xml files on the device.
And everytime the xml or the image is requested by the application it should check
if a newer version is found on the server.
Im sending the date "Mon, 19 Jul 2010 11:20:22 GMT"
And im receiving the date "Mon, 19 Jul 2010 10:20:17 GMT" from the server.
Usually it should work and return a 304 status.


if (Titanium.Network.online)
{
      var c = Titanium.Network.createHTTPClient();
      if (c.status == 304)
      {
        // XML File not necessary - Clientlog File is newer
        console.log('Use Client XML File - is newer than the server XML');
        fn_end(file_obj);
        return;
      }
      // ...here will follow some code to store the files on the device

      c.open('GET', url);
      c.setRequestHeader("If-Modified-Since", "Mon, 19 Jul 2010 11:20:22 GMT");
      c.send();
}

Comments

  1. Don Thorp 2011-04-15

    What platform(s) are you reporting the issue on?

  2. marco.schierhorn (at gmail) 2011-04-15

    Hey Don,

    thanks for the response.
    Im reporting this issue on Android using Titanium SDK 1.3.0 and Android SDK 2.1.
    Currently im only testing it on the SDK/Emulator and not on a real phone.

  3. Robby 2011-04-15

    Since this ticket has the attention of the devs, it looks like setRequestHeader is broken under SDK 1.4.0 with iOS as well. I am having problems setting it with basically the same code as used above:

       var myUsername = 'testuser';
       var myPassword = 'testpass';
       
       var request = Titanium.Network.createHTTPClient({
               onload:function(e) {
                   if (request.status != 200 && request.status != 201) {
                       request.onerror(e);
                       return;
                   }
               },
               onerror:function(e) {
                   Ti.API.info("Got Error: "
                       + e.error);
               }
           });
       
       request.open('GET', 'https://myserverurl', true);
       request.setRequestHeader('Authorization','Basic '  + Titanium.Utils.base64encode(myUsername + ':' + myPassword));
       request.send();
       

    On the server side (Google App engine), I examine the headers and see that 'Authorization' isn't set. I get the same results for 'PUT' and 'POST' as well (header not set). This happens with the iPhone simulator (iOS SDK 4.0.1). About to try it out on hardware now...

    I've looked at the ObjC source of it...looks very straightforward. Perhaps it is a scoping issue?

    Since the original author had an Android issue, I can create a new ticket for this if necessary.

    Robby

  4. Jacob Avlund 2011-04-15

    It appears that the problem has to do with setRequestHeader silently failing if there's a line break in the value parameter - which there will be in regular use of base64encode.

    My suggestion is to:

    a) make it possible to call base64encode with a parameter to get a result without line breaks (which otherwise will occur for large strings)
    b) log an error message if the setRequestHeader function is called with a string with line breaks (or just remove the line breaks from the string)

    I described the error and a workaround in greater detail here: http://developer.appcelerator.com/question/102491/bug-discovered-base64-line-breaks#182241"> http://developer.appcelerator.com/question/102491/bug-discovered-ba... , since I was too daft to find this Lighthouse site on my own.

JSON Source