bug 528292: convey the mForceAllowThirdPartyCookie flag when setting up a replacement channel for a redirected HTTP request; r,sr=bzbarsky
authorMyk Melez <myk@mozilla.org>
Sun, 13 Dec 2009 11:04:03 -0800
changeset 35679 961c37d6fc0461316322711d13d4f77b59c7fd55
parent 35678 25e1f548b4ae266bf67396dfb14481675772c93a
child 35680 006787c678a8426945a70ea2b50791f30297e6c0
push id10675
push usermyk@mozilla.com
push dateSun, 13 Dec 2009 19:05:05 +0000
treeherdermozilla-central@961c37d6fc04 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs528292
milestone1.9.3a1pre
bug 528292: convey the mForceAllowThirdPartyCookie flag when setting up a replacement channel for a redirected HTTP request; r,sr=bzbarsky
netwerk/protocol/http/src/nsHttpChannel.cpp
netwerk/test/unit/test_bug528292.js
--- a/netwerk/protocol/http/src/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/src/nsHttpChannel.cpp
@@ -2829,16 +2829,19 @@ nsHttpChannel::SetupReplacementChannel(n
         httpChannel->SetReferrer(mReferrer);
     // convey the mAllowPipelining flag
     httpChannel->SetAllowPipelining(mAllowPipelining);
     // convey the new redirection limit
     httpChannel->SetRedirectionLimit(mRedirectionLimit - 1);
 
     nsCOMPtr<nsIHttpChannelInternal> httpInternal = do_QueryInterface(newChannel);
     if (httpInternal) {
+        // convey the mForceAllowThirdPartyCookie flag
+        httpInternal->SetForceAllowThirdPartyCookie(mForceAllowThirdPartyCookie);
+
         // update the DocumentURI indicator since we are being redirected.
         // if this was a top-level document channel, then the new channel
         // should have its mDocumentURI point to newURI; otherwise, we
         // just need to pass along our mDocumentURI to the new channel.
         if (newURI && (mURI == mDocumentURI))
             httpInternal->SetDocumentURI(newURI);
         else
             httpInternal->SetDocumentURI(mDocumentURI);
new file mode 100644
--- /dev/null
+++ b/netwerk/test/unit/test_bug528292.js
@@ -0,0 +1,67 @@
+do_load_httpd_js();
+
+const sentCookieVal     = "foo=bar";
+const responseBody      = "response body";
+const baseURL           = "http://localhost:4444";
+const preRedirectPath   = "/528292/pre-redirect";
+const preRedirectURL    = baseURL + preRedirectPath;
+const postRedirectPath  = "/528292/post-redirect";
+const postRedirectURL   = baseURL + postRedirectPath;
+var   httpServer        = null;
+var   receivedCookieVal = null;
+
+function preRedirectHandler(metadata, response)
+{
+  response.setStatusLine(metadata.httpVersion, 302, "Found");
+  response.setHeader("Location", postRedirectURL, false);
+  return;
+}
+
+function postRedirectHandler(metadata, response)
+{
+  receivedCookieVal = metadata.getHeader("Cookie");
+  response.setHeader("Content-Type", "text/plain");
+  response.bodyOutputStream.write(responseBody, responseBody.length);
+}
+
+function run_test()
+{
+  // Start the HTTP server.
+  httpServer = new nsHttpServer();
+  httpServer.registerPathHandler(preRedirectPath, preRedirectHandler);
+  httpServer.registerPathHandler(postRedirectPath, postRedirectHandler);
+  httpServer.start(4444);
+
+  // Disable third-party cookies in general.
+  Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch).
+    setIntPref("network.cookie.cookieBehavior", 1);
+
+  var ioService = Cc["@mozilla.org/network/io-service;1"].
+                  getService(Ci.nsIIOService);
+
+  // Set up a channel with forceAllowThirdPartyCookie set to true.  We'll use
+  // the channel both to set a cookie (since nsICookieService::setCookieString
+  // requires such a channel in order to successfully set a cookie) and then
+  // to load the pre-redirect URI.
+  var chan = ioService.newChannel(preRedirectURL, "", null).
+             QueryInterface(Ci.nsIHttpChannel).
+             QueryInterface(Ci.nsIHttpChannelInternal);
+  chan.forceAllowThirdPartyCookie = true;
+
+  // Set a cookie on one of the URIs.  It doesn't matter which one, since
+  // they're both from the same host, which is enough for the cookie service
+  // to send the cookie with both requests.
+  var postRedirectURI = ioService.newURI(postRedirectURL, "", null);
+  Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService).
+    setCookieString(postRedirectURI, null, sentCookieVal, chan);
+
+  // Load the pre-redirect URI.
+  chan.asyncOpen(new ChannelListener(finish_test, null), null);
+  do_test_pending();
+}
+
+function finish_test(event)
+{
+  do_check_eq(receivedCookieVal, sentCookieVal);
+  httpServer.stop(do_test_finished);
+}