Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13885] iOS: I can't send more than one cookie

GitHub Issuen/a
TypeBug
PriorityLow
StatusReopened
ResolutionUnresolved
Affected Version/sRelease 3.1.0, Release 3.2.0
Fix Version/sn/a
ComponentsiOS
Labelsparity
ReporterMatej
AssigneeUnknown
Created2013-05-13T12:07:20.000+0000
Updated2018-02-28T20:03:59.000+0000

Description

*Problem* Unfortunately with an iOS I can't use/send more than one cookie. With Android it is working without any problems. *Test case*
var win = Titanium.UI.createWindow();

var xhr = Ti.Network.createHTTPClient();
xhr.open("GET", "http://www.some.where");
xhr.setRequestHeader("Cookie", "cookieName=value; nextCookieName=nextValue;");
xhr.send();

win.open();
*Log*
[ERROR] invalid arguments for setting cookie. value should be in the format 'name=value'. in -[TiNetworkHTTPClientProxy setRequestHeader:] (TiNetworkHTTPClientProxy.m:465) [WARN] Exception in event callback. { line = xxx; message = "invalid arguments for setting cookie. value should be in the format 'name=value'. in -[TiNetworkHTTPClientProxy setRequestHeader:] (TiNetworkHTTPClientProxy.m:465)"; sourceId = 366760928; sourceURL = "file://localhost/Users/xxx/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/1EC7C0B6-34E5-4D96-9D79-0685610566E7/xxx.app/xxx.js"; }
*Workarounds* http://developer.appcelerator.com/question/120728/set-cookies-using-setrequestheader--crashed-
if (Titanium.Platform.name == 'iPhone OS')  
{
    xhr.setRequestHeader("Cookie", "cookie1=value1");
    xhr.setRequestHeader("Cookie", "cookie2=value2");
}
else
{
    var cookieString = "cookie1=value1; cookie2=value2;";
    xhr.setRequestHeader('Cookie', cookieString);
}

Comments

  1. Tony Lukasavage 2013-05-15

    have you referenced this Q&A? http://developer.appcelerator.com/question/120728/set-cookies-using-setrequestheader--crashed-
  2. Matej 2013-05-15

    Yes, I know that I can solve that problem like this... But firstly: If I have too many cookie there's too many work with this. On Android is it working without any problems. I would be very happy if it worked also with iOS. I think that much better is fix this main bug in the Ti than fix it somewhere in the normal application every time. Problem is that this is not only one bug in the Ti/My app. There are too many bugs and my source code than looks absolutely terrible (Everywhere some fix). Also I have to make too much changes between iOS/Android because... Simply awfully. Thank you for understanding ;)
  3. Tony Lukasavage 2013-05-15

    Absolutely understood. I just wanted to have a workaround at your disposal until this can be properly escalated to the platform team. It seems to be quite clearly a parity issue, that as you state, developers should not need to account for and should be fixed in Titanium.
  4. Daniel Sefton 2013-05-15

    So I'm guessing that the following
    webView.evalJS('document.cookie;')
    returns multiple variables like
    "cookie1=value1; cookie2=value2;"
    Is that right? It would be useful to have a complete simple test case that I can drop into an app.js, run and reproduce the error. With that I can escalate it to engineering. Thanks.
  5. Matej 2013-05-16

    Yes, you are right. Here is little sample:
       var win = Titanium.UI.createWindow();
       
       var xhr = Ti.Network.createHTTPClient();
       xhr.open("GET", "http://www.some.where");
       xhr.setRequestHeader("Cookie", "cookieName=value; nextCookieName=nextValue;");
       xhr.send();
       
       win.open();
       
  6. Daniel Sefton 2013-05-16

    Tested and confirmed on iOS 6 simulator with Ti SDK 3.1 GA and 3.2 CI.
  7. Vance Lucas 2013-11-15

    Just ran into this. If cookie values have to be set separately for some reason on iOS, the Titanium code should definitely handle this. Users apps shouldn't hard crash for attempting to set a completely valid and normal "Cookie" header value.
  8. Brian Knorr 2014-04-10

    Any idea when this issue will be addressed?

JSON Source