diff --git a/content/base/src/nsCrossSiteListenerProxy.cpp b/content/base/src/nsCrossSiteListenerProxy.cpp index 6bcde723c62f..d79cfb158720 100644 --- a/content/base/src/nsCrossSiteListenerProxy.cpp +++ b/content/base/src/nsCrossSiteListenerProxy.cpp @@ -59,6 +59,7 @@ #include "prtime.h" #include "nsClassHashtable.h" #include "nsHashKeys.h" +#include "nsStreamUtils.h" #define PREFLIGHT_CACHE_SIZE 100 @@ -1002,7 +1003,8 @@ nsCORSPreflightListener::OnDataAvailable(nsIRequest *aRequest, PRUint32 sourceOffset, PRUint32 count) { - return NS_OK; + PRUint32 totalRead; + return inStr->ReadSegments(NS_DiscardSegment, nsnull, count, &totalRead); } NS_IMETHODIMP diff --git a/content/base/test/file_CrossSiteXHR_server.sjs b/content/base/test/file_CrossSiteXHR_server.sjs index e42c7232af3f..f1d9bb720a1b 100644 --- a/content/base/test/file_CrossSiteXHR_server.sjs +++ b/content/base/test/file_CrossSiteXHR_server.sjs @@ -151,6 +151,10 @@ function handleRequest(request, response) response.setHeader("Content-Type", "application/xml", false); response.write("hello pass\n"); } + if (isPreflight && "preflightBody" in query) { + response.setHeader("Content-Type", "text/plain", false); + response.write(query.preflightBody); + } } function sendHttp500(response, text) { diff --git a/content/base/test/test_CrossSiteXHR.html b/content/base/test/test_CrossSiteXHR.html index df5abb8c3252..fef9720aa24a 100644 --- a/content/base/test/test_CrossSiteXHR.html +++ b/content/base/test/test_CrossSiteXHR.html @@ -567,6 +567,13 @@ function runTest() { exposeHeaders: " , ,,y-my-header,z-my-header, ", expectedResponseHeaders: ["y-my-header"], }, + + // Check that sending a body in the OPTIONS response works + { pass: 1, + method: "DELETE", + allowMethods: "DELETE", + preflightBody: "I'm a preflight response body", + }, ]; if (!runPreflightTests) { @@ -635,6 +642,8 @@ function runTest() { req.url += "&responseHeaders=" + escape(test.responseHeaders.toSource()); if (test.exposeHeaders) req.url += "&exposeHeaders=" + escape(test.exposeHeaders); + if (test.preflightBody) + req.url += "&preflightBody=" + escape(test.preflightBody); loaderWindow.postMessage(req.toSource(), origin); res = eval(yield);