Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-2849] Android: Set-Cookie Response Headers Only Returns Max of One Cookie

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2012-01-04T10:33:06.000+0000
Affected Version/sRelease 1.5.1, Release 1.6.0
Fix Version/sSprint 2011-39, Release 1.7.4, Release 1.8.0
ComponentsAndroid
Labelsenterprise, module_network, qe-testadded
ReporterDawson Toth
AssigneeAllen Yeung
Created2011-04-15T03:31:06.000+0000
Updated2014-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

FileDateSize
cookieslogcat.rtf2011-04-15T03:31:07.000+00003297

Comments

  1. Don Thorp 2011-04-15

    bumping the priority for next scheduling round.

  2. Miguel Vizcaino 2011-06-29

       var win = Titanium.UI.createWindow({
       	backgroundColor:'white'
       });
       var view = Ti.UI.createView({
       	backgroundColor:'blue',
       	top:10,
       	bottom:10,
       	right:10,
       	left:10
       });
       
       var button = Titanium.UI.createButton({
          title: 'Click',
          top:230
       });
       
       button.addEventListener('click',function(e)
       {
       	var url = 'http://developer.appcelerator.com';
       	var xhr = Ti.Network.createHTTPClient();
       	xhr.onload = function(e) {
       		alert(this.getResponseHeader('Set-Cookie'));
       	};
       	xhr.open('GET', url);
       	xhr.setRequestHeader('Cookie', null);
       	xhr.send();
       });
       view.add(button);
       win.add(view);
       win.open();
       

    Associated Helpdesk Ticket

    http://support.appcelerator.com/tickets/APP-937711

    Customer Priority needs to be increased.

  3. Anirudh Nagesh 2011-07-08

    Associated helpdesk ticket.

    appc.me/c/APP-937711 This is very critical for one of the customers.
  4. Dawson Toth 2011-07-14

    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?
  5. Dawson Toth 2011-07-14

    Updated sample code to point to a working server.
  6. Natalie Huynh 2011-08-25

    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
  7. Alan Vaghti 2011-08-26

    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.
  8. Michael Pettiford 2012-01-04

    Reopening/closing to add/remove labels
  9. jithinpv 2013-11-25

    Anvil test case added. PR link: https://github.com/appcelerator/titanium_mobile/pull/5011

JSON Source