Backed out changeset a8b7ae2ed577 (bug 1337543) draft
authorSebastian Hengst <archaeopteryx@coole-files.de>
Mon, 13 Feb 2017 18:59:48 +0100
changeset 485877 9143c69f39ee94f304ea46b8ba258b7e92b6f1a4
parent 485876 2f48db94ca47fddb30e2e7861af583cb89ab365c
child 485878 f18c283a8587f2b923184bc1b47ae43d8a36adc9
push id45870
push userbmo:kechen@mozilla.com
push dateFri, 17 Feb 2017 09:36:54 +0000
bugs1337543
milestone54.0a1
backs outa8b7ae2ed5775e61ea5a3c23088a6da415da0cb4
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);