[TIMOB-2849] Android: Set-Cookie Response Headers Only Returns Max of One Cookie
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-01-04T10:33:06.000+0000 |
Affected Version/s | Release 1.5.1, Release 1.6.0 |
Fix Version/s | Sprint 2011-39, Release 1.7.4, Release 1.8.0 |
Components | Android |
Labels | enterprise, module_network, qe-testadded |
Reporter | Dawson Toth |
Assignee | Allen Yeung |
Created | 2011-04-15T03:31:06.000+0000 |
Updated | 2014-03-13T17:45:14.000+0000 |
Description
Problem
On Android, the "Set-Cookie" response header from a Ti.Network.HTTPClient will only return a max of one cookie, even if more than one cookie is set.
For example, iPhone correctly returns the following:
this.getResponseHeader('Set-Cookie') == 'CookieName1=CookieValue1; path=/, CookieName2=CookieValue2; path=/';
But Android returns the following, neglecting the second value:
this.getResponseHeader('Set-Cookie') == 'CookieName1=CookieValue1; path=/';
Expected Behavior
A comma delimited string of name=value; path=/ cookie strings should be returned, just like on iPhone.
Tested On
Tested with Titanium Mobile SDK 1.5.1 and 1.6.0 (01/06/11).
FAILED on Android Device Samsung Epic 2.1
PASSED on iPhone Simulator
Sample Code
The sample code hits a public page I have created. The "Get or Set Cookies" button makes a request to the page, and the page will either a) echo the cookies we sent or b) if we didn't send cookies, send us two cookies. "Clear Cookies" asks the server to expire the cookies.
var win = Titanium.UI.createWindow({ backgroundColor:'#fff' });
var testServer = 'http://appc.me/Test/Cookies/';
/**
* Create a text area to show responses from the server.
*/
var response = Titanium.UI.createTextArea({
left: 0, right: 0, top: 0, bottom: 30,
value: 'Click a button below, and the response from the server will show up here!'
});
win.add(response);
/**
* Create a button that will hit a page on a test server that echoes any cookies we send it, or sends us two cookies.
*/
var getOrSetCookies = Titanium.UI.createButton({ title : 'Get or Set Cookies', left: 0, bottom: 0, width: 150, height: 30 });
getOrSetCookies.addEventListener('click', function(e) {
var xhr = Ti.Network.createHTTPClient();
xhr.onload = function(e) {
response.value = this.responseText
+ '\n\nthis.getResponseHeader(\'Set-Cookie\'): '
+ this.getResponseHeader('Set-Cookie');
};
xhr.open('GET', testServer + '?count=2&clear=false');
xhr.send();
});
win.add(getOrSetCookies);
/**
* Create a button that will clear the cookies on the server (set them to expire). It will tell us how many were cleared.
*/
var clearCookies = Titanium.UI.createButton({ title : 'Clear Cookies', right: 0, bottom: 0, width: 150, height: 30 });
clearCookies.addEventListener('click', function(e) {
var xhr = Ti.Network.createHTTPClient();
xhr.onload = function(e) {
response.value = this.responseText
+ '\n\nthis.getResponseHeader(\'Set-Cookie\'): '
+ this.getResponseHeader('Set-Cookie');
};
xhr.open('GET', testServer + '?count=2&clear=true');
xhr.send();
});
win.add(clearCookies);
win.open();
Log from Device
Attached is the output from adb -d logcat. Doesn't have terribly useful information...
Associated Helpdesk Ticket
http://developer.appcelerator.com/helpdesk/view/58531">http://developer.appcelerator.com/helpdesk/view/58531
Attachments
File | Date | Size |
---|---|---|
cookieslogcat.rtf | 2011-04-15T03:31:07.000+0000 | 3297 |
bumping the priority for next scheduling round.
Associated Helpdesk Ticket
http://support.appcelerator.com/tickets/APP-937711Customer Priority needs to be increased.
Associated helpdesk ticket.
appc.me/c/APP-937711 This is very critical for one of the customers.Bumped priority up, per email from Kincy. An enterprise client is waiting on this, and there isn't a workaround that I've been able to come up with. Can I provide more info on this, or is there anything I can do to help?
Updated sample code to point to a working server.
Tested with 1.8.0.v20110819142548 Motorola Xoom 3.2 Nexus One 2.2.2 Clear Cookies show: Set 0 cookies to expire a year ago iPhone 4.3.4 iPad2 4.3.2 Clear Cookies show: Set 2 cookies to expire a year ago with the cookies and expire date
Tested with same SDK as Natalie and got the same Android message (Clear Cookies show: Set 0 cookies to expire a year ago) with an Galaxy Tab 10.1 running 3.1.
Reopening/closing to add/remove labels
Anvil test case added. PR link: https://github.com/appcelerator/titanium_mobile/pull/5011