Backed out changeset a8b7ae2ed577 (bug 1337543)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Mon, 13 Feb 2017 18:59:48 +0100
changeset 342531 d013f110b38b722c813e2341a4a31e3b1dfc06c6
parent 342530 4c1d8f705b895067e21ccbcc642b6a25b78fa58a
child 342532 34a69397de640dad159f81df1162331d3ed7b579
push id86897
push userarchaeopteryx@coole-files.de
push dateMon, 13 Feb 2017 18:01:23 +0000
treeherdermozilla-inbound@b7e862302157 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1337543
milestone54.0a1
backs outa8b7ae2ed5775e61ea5a3c23088a6da415da0cb4
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset a8b7ae2ed577 (bug 1337543)
dom/fetch/FetchDriver.cpp
dom/fetch/InternalHeaders.cpp
dom/fetch/InternalHeaders.h
--- a/dom/fetch/FetchDriver.cpp
+++ b/dom/fetch/FetchDriver.cpp
@@ -8,16 +8,17 @@
 #include "mozilla/dom/FetchDriver.h"
 
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "nsIDocument.h"
 #include "nsIInputStream.h"
 #include "nsIOutputStream.h"
 #include "nsIHttpChannel.h"
 #include "nsIHttpChannelInternal.h"
+#include "nsIHttpHeaderVisitor.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIThreadRetargetableRequest.h"
 #include "nsIUploadChannel2.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIPipe.h"
 
 #include "nsContentPolicyUtils.h"
 #include "nsDataHandler.h"
@@ -410,16 +411,48 @@ FetchDriver::FailWithNetworkError()
 #ifdef DEBUG
     mResponseAvailableCalled = true;
 #endif
     mObserver->OnResponseEnd();
     mObserver = nullptr;
   }
 }
 
+namespace {
+class FillResponseHeaders final : public nsIHttpHeaderVisitor {
+  InternalResponse* mResponse;
+
+  ~FillResponseHeaders()
+  { }
+public:
+  NS_DECL_ISUPPORTS
+
+  explicit FillResponseHeaders(InternalResponse* aResponse)
+    : mResponse(aResponse)
+  {
+  }
+
+  NS_IMETHOD
+  VisitHeader(const nsACString & aHeader, const nsACString & aValue) override
+  {
+    ErrorResult result;
+    mResponse->Headers()->Append(aHeader, aValue, result);
+    if (result.Failed()) {
+      NS_WARNING(nsPrintfCString("Fetch ignoring illegal header - '%s': '%s'",
+                                 PromiseFlatCString(aHeader).get(),
+                                 PromiseFlatCString(aValue).get()).get());
+      result.SuppressException();
+    }
+    return NS_OK;
+  }
+};
+
+NS_IMPL_ISUPPORTS(FillResponseHeaders, nsIHttpHeaderVisitor)
+} // namespace
+
 NS_IMETHODIMP
 FetchDriver::OnStartRequest(nsIRequest* aRequest,
                             nsISupports* aContext)
 {
   workers::AssertIsOnMainThread();
 
   // Note, this can be called multiple times if we are doing an opaqueredirect.
   // In that case we will get a simulated OnStartRequest() and then the real
@@ -463,17 +496,21 @@ FetchDriver::OnStartRequest(nsIRequest* 
       }
     }
 
     nsAutoCString statusText;
     httpChannel->GetResponseStatusText(statusText);
 
     response = new InternalResponse(responseStatus, statusText);
 
-    response->Headers()->FillResponseHeaders(httpChannel);
+    RefPtr<FillResponseHeaders> visitor = new FillResponseHeaders(response);
+    rv = httpChannel->VisitResponseHeaders(visitor);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      NS_WARNING("Failed to visit all headers.");
+    }
 
     // If Content-Encoding or Transfer-Encoding headers are set, then the actual
     // Content-Length (which refer to the decoded data) is obscured behind the encodings.
     ErrorResult result;
     if (response->Headers()->Has(NS_LITERAL_CSTRING("content-encoding"), result) ||
         response->Headers()->Has(NS_LITERAL_CSTRING("transfer-encoding"), result)) {
       NS_WARNING("Cannot know response Content-Length due to presence of Content-Encoding "
                  "or Transfer-Encoding headers.");
--- a/dom/fetch/InternalHeaders.cpp
+++ b/dom/fetch/InternalHeaders.cpp
@@ -6,17 +6,16 @@
 
 #include "mozilla/dom/InternalHeaders.h"
 
 #include "mozilla/dom/FetchTypes.h"
 #include "mozilla/ErrorResult.h"
 
 #include "nsCharSeparatedTokenizer.h"
 #include "nsContentUtils.h"
-#include "nsIHttpHeaderVisitor.h"
 #include "nsNetUtil.h"
 #include "nsReadableUtils.h"
 
 namespace mozilla {
 namespace dom {
 
 InternalHeaders::InternalHeaders(const nsTArray<Entry>&& aHeaders,
                                  HeadersGuardEnum aGuard)
@@ -310,58 +309,16 @@ InternalHeaders::Fill(const MozMap<nsCSt
 {
   nsTArray<nsString> keys;
   aInit.GetKeys(keys);
   for (uint32_t i = 0; i < keys.Length() && !aRv.Failed(); ++i) {
     Append(NS_ConvertUTF16toUTF8(keys[i]), aInit.Get(keys[i]), aRv);
   }
 }
 
-namespace {
-
-class FillHeaders final : public nsIHttpHeaderVisitor
-{
-  RefPtr<InternalHeaders> mInternalHeaders;
-
-  ~FillHeaders() = default;
-
-public:
-  NS_DECL_ISUPPORTS
-
-  explicit FillHeaders(InternalHeaders* aInternalHeaders)
-    : mInternalHeaders(aInternalHeaders)
-  {
-    MOZ_DIAGNOSTIC_ASSERT(mInternalHeaders);
-  }
-
-  NS_IMETHOD
-  VisitHeader(const nsACString& aHeader, const nsACString& aValue) override
-  {
-    IgnoredErrorResult result;
-    mInternalHeaders->Append(aHeader, aValue, result);
-    return NS_OK;
-  }
-};
-
-NS_IMPL_ISUPPORTS(FillHeaders, nsIHttpHeaderVisitor)
-
-} // namespace
-
-void
-InternalHeaders::FillResponseHeaders(nsIRequest* aRequest)
-{
-  nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aRequest);
-  if (!httpChannel) {
-    return;
-  }
-
-  RefPtr<FillHeaders> visitor = new FillHeaders(this);
-  httpChannel->VisitResponseHeaders(visitor);
-}
-
 bool
 InternalHeaders::HasOnlySimpleHeaders() const
 {
   for (uint32_t i = 0; i < mList.Length(); ++i) {
     if (!IsSimpleHeader(mList[i].mName, mList[i].mValue)) {
       return false;
     }
   }
--- a/dom/fetch/InternalHeaders.h
+++ b/dom/fetch/InternalHeaders.h
@@ -97,17 +97,16 @@ public:
   void Clear();
 
   HeadersGuardEnum Guard() const { return mGuard; }
   void SetGuard(HeadersGuardEnum aGuard, ErrorResult& aRv);
 
   void Fill(const InternalHeaders& aInit, ErrorResult& aRv);
   void Fill(const Sequence<Sequence<nsCString>>& aInit, ErrorResult& aRv);
   void Fill(const MozMap<nsCString>& aInit, ErrorResult& aRv);
-  void FillResponseHeaders(nsIRequest* aRequest);
 
   bool HasOnlySimpleHeaders() const;
 
   bool HasRevalidationHeaders() const;
 
   static already_AddRefed<InternalHeaders>
   BasicHeaders(InternalHeaders* aHeaders);