Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-2849

Android: Set-Cookie Response Headers Only Returns Max of One Cookie

    Details

      Description

      {html}<div><h1>Problem</h1>
      <p>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.</p>
      <p>For example, iPhone correctly returns the following:</p>
      <pre>
      <code class=
      "javascript">this.getResponseHeader('Set-Cookie') == 'CookieName1=CookieValue1; path=/, CookieName2=CookieValue2; path=/';</code>
      </pre>
      <p>But Android returns the following, neglecting the second
      value:</p>
      <pre>
      <code class=
      "javascript">this.getResponseHeader('Set-Cookie') == 'CookieName1=CookieValue1; path=/';</code>
      </pre>
      <h1>Expected Behavior</h1>
      <p>A comma delimited string of name=value; path=/ cookie strings
      should be returned, just like on iPhone.</p>
      <h1>Tested On</h1>
      <p>Tested with Titanium Mobile SDK 1.5.1 and 1.6.0 (01/06/11).<br>
      FAILED on Android Device Samsung Epic 2.1<br>
      PASSED on iPhone Simulator</p>
      <h1>Sample Code</h1>
      <p>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.</p>
      <pre>
      <code class=
      "javascript">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();</code>
      </pre>
      <h1>Log from Device</h1>
      <p>Attached is the output from adb -d logcat. Doesn't have terribly
      useful information...</p>
      <h2>Associated Helpdesk Ticket</h2>
      <p><a href=
      "http://developer.appcelerator.com/helpdesk/view/58531">http://developer.appcelerator.com/helpdesk/view/58531</a></p></div>{html}

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ayeung Allen Yeung
                Reporter:
                dtoth Dawson Toth
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-2474
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Integration