Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3095] Android: Our download cache does not respect the standard of case-insensitive headers

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T02:00:54.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.6.0 M09
ComponentsAndroid
Labelsandroid, defect, release-1.6.0, reported-1.6.0
ReporterBill Dawson
AssigneeDon Thorp
Created2011-04-15T03:36:46.000+0000
Updated2011-04-17T02:00:54.000+0000

Description

For example, we check for "Cache-Control" and would miss "cache-control". According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2">this headers are case-insensitive.

Failcase app.js:


Titanium.UI.setBackgroundColor('#000');
var win = Titanium.UI.createWindow({  
    title:'Test',
    backgroundColor:'#000',
    exitOnClose: true
});
var thisURL = "module=MultiSites&action=getEvolutionGraph&period=day&date=2011-01-04,2011-02-02&evolutionBy=visits&columns=nb_visits&idSite=7&idsite=7&viewDataTable=sparkline";

var paramArray = thisURL.split("&");
for(var i=0,ilen=paramArray.length;i<ilen;i++){
    var thisKeyValue = paramArray[i].split("=");
    thisKeyValue[1] = Ti.Network.encodeURIComponent(thisKeyValue[1]);
    paramArray[i] = thisKeyValue.join("=");
}
var encodedURI = paramArray.join("&");
var encodedURL = "http://demo.piwik.org/index.php?" + encodedURI;
Ti.API.info(encodedURL);

var imageView = Ti.UI.createImageView({
    image: encodedURL
});
 
win.add(imageView);
win.open();

Follow these steps:

  • Create a new titanium project and make the code above its app.js.

  • Run the app. The app will crash because of #3094, but that's okay because it's already written to the cache.

  • At the command line do the following commands.

adb shell
cd /sdcard/[your app id]/remote-image-cache
ls
cat *.hdr

(But of course replace [your app id] with your app's id.)

After entering the ls command, you will see files listed. There should not be any, because the file that is being cached there should not have been cached. You can see that because of the cat command which shows you the http headers retrieved upon getting the remote file. One of the headers is cache-control and it indicates that the file should not be cached. But it was, and the reason is because we were looking for Cache-Control in a case-sensitive fashion, so we missed cache-control.

Important notes re testing the fix

Once you're ready to test the fix, you need to be sure to clear the cache to get rid of those files that shouldn't have been there in the first place.

adb shell
cd /sdcard
rm -r [your app id]

And when you test the fix, don't be shocked if no image at all appears on screen. That's bug #3093. For this test, you just want to be sure that after you launch the app there is nothing in the remote-image-cache for your app.

Comments

  1. Bill Dawson 2011-04-15

    (from [4f7ca257dc0c13829996d2c6503cce5effff8388]) Access headers in case-insensitive fashion, do not write out transfer-encoding: chunked header, fix regular expression that checks for no caching, fix removal of uri from set of uris currently downloading. [#3095 state:fixed-in-qa][#3094 state:fixed-in-qa] https://github.com/appcelerator/titanium_mobile/commit/4f7ca257dc0c13829996d2c6503cce5effff8388"> https://github.com/appcelerator/titanium_mobile/commit/4f7ca257dc0c...

  2. Opie Cyrus 2011-04-15

    verified emulator 2.2

  3. Bill Dawson 2011-04-15

    (from [d08271606cb059c5bc0d3be4a0ec809ba990fe29]) Access headers in case-insensitive fashion, do not write out transfer-encoding: chunked header, fix regular expression that checks for no caching, fix removal of uri from set of uris currently downloading. [#3095 state:fixed-in-qa][#3094 state:fixed-in-qa] https://github.com/appcelerator/titanium_mobile/commit/d08271606cb059c5bc0d3be4a0ec809ba990fe29"> https://github.com/appcelerator/titanium_mobile/commit/d08271606cb0...

  4. Opie Cyrus 2011-04-15

    Setting back to resolved. Was set to fixed-in-qa by cherry pick.

JSON Source