diff options
Diffstat (limited to 'dom/fetch')
-rw-r--r-- | dom/fetch/FetchDriver.cpp | 6 | ||||
-rw-r--r-- | dom/fetch/InternalHeaders.cpp | 25 | ||||
-rw-r--r-- | dom/fetch/InternalHeaders.h | 4 | ||||
-rw-r--r-- | dom/fetch/InternalResponse.cpp | 7 | ||||
-rw-r--r-- | dom/fetch/InternalResponse.h | 10 |
5 files changed, 37 insertions, 15 deletions
diff --git a/dom/fetch/FetchDriver.cpp b/dom/fetch/FetchDriver.cpp index e755edeb3b..10ef54c38f 100644 --- a/dom/fetch/FetchDriver.cpp +++ b/dom/fetch/FetchDriver.cpp @@ -536,7 +536,8 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest, nsAutoCString statusText; httpChannel->GetResponseStatusText(statusText); - response = new InternalResponse(responseStatus, statusText); + response = new InternalResponse(responseStatus, statusText, + mRequest->GetCredentialsMode()); RefPtr<FillResponseHeaders> visitor = new FillResponseHeaders(response); rv = httpChannel->VisitResponseHeaders(visitor); @@ -555,7 +556,8 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest, } MOZ_ASSERT(!result.Failed()); } else { - response = new InternalResponse(200, NS_LITERAL_CSTRING("OK")); + response = new InternalResponse(200, NS_LITERAL_CSTRING("OK"), + mRequest->GetCredentialsMode()); ErrorResult result; nsAutoCString contentType; diff --git a/dom/fetch/InternalHeaders.cpp b/dom/fetch/InternalHeaders.cpp index b659d14efe..0448d84731 100644 --- a/dom/fetch/InternalHeaders.cpp +++ b/dom/fetch/InternalHeaders.cpp @@ -364,7 +364,7 @@ InternalHeaders::BasicHeaders(InternalHeaders* aHeaders) // static already_AddRefed<InternalHeaders> -InternalHeaders::CORSHeaders(InternalHeaders* aHeaders) +InternalHeaders::CORSHeaders(InternalHeaders* aHeaders, RequestCredentials aCredentialsMode) { RefPtr<InternalHeaders> cors = new InternalHeaders(aHeaders->mGuard); ErrorResult result; @@ -373,6 +373,7 @@ InternalHeaders::CORSHeaders(InternalHeaders* aHeaders) aHeaders->GetFirst(NS_LITERAL_CSTRING("Access-Control-Expose-Headers"), acExposedNames, result); MOZ_ASSERT(!result.Failed()); + bool allowAllHeaders = false; AutoTArray<nsCString, 5> exposeNamesArray; nsCCharSeparatedTokenizer exposeTokens(acExposedNames, ','); while (exposeTokens.hasMoreTokens()) { @@ -388,19 +389,27 @@ InternalHeaders::CORSHeaders(InternalHeaders* aHeaders) break; } + if (token.EqualsLiteral("*") && + aCredentialsMode != RequestCredentials::Include) { + allowAllHeaders = true; + } + exposeNamesArray.AppendElement(token); } nsCaseInsensitiveCStringArrayComparator comp; for (uint32_t i = 0; i < aHeaders->mList.Length(); ++i) { const Entry& entry = aHeaders->mList[i]; - if (entry.mName.EqualsASCII("cache-control") || - entry.mName.EqualsASCII("content-language") || - entry.mName.EqualsASCII("content-type") || - entry.mName.EqualsASCII("expires") || - entry.mName.EqualsASCII("last-modified") || - entry.mName.EqualsASCII("pragma") || - exposeNamesArray.Contains(entry.mName, comp)) { + if (allowAllHeaders) { + cors->Append(entry.mName, entry.mValue, result); + MOZ_ASSERT(!result.Failed()); + } else if (entry.mName.EqualsASCII("cache-control") || + entry.mName.EqualsASCII("content-language") || + entry.mName.EqualsASCII("content-type") || + entry.mName.EqualsASCII("expires") || + entry.mName.EqualsASCII("last-modified") || + entry.mName.EqualsASCII("pragma") || + exposeNamesArray.Contains(entry.mName, comp)) { cors->Append(entry.mName, entry.mValue, result); MOZ_ASSERT(!result.Failed()); } diff --git a/dom/fetch/InternalHeaders.h b/dom/fetch/InternalHeaders.h index a904ba595a..ae9f2811a2 100644 --- a/dom/fetch/InternalHeaders.h +++ b/dom/fetch/InternalHeaders.h @@ -8,6 +8,7 @@ // needed for HeadersGuardEnum. #include "mozilla/dom/HeadersBinding.h" +#include "mozilla/dom/RequestBinding.h" #include "mozilla/dom/UnionTypes.h" #include "nsClassHashtable.h" @@ -122,7 +123,8 @@ public: BasicHeaders(InternalHeaders* aHeaders); static already_AddRefed<InternalHeaders> - CORSHeaders(InternalHeaders* aHeaders); + CORSHeaders(InternalHeaders* aHeaders, + RequestCredentials mCredentialsMode = RequestCredentials::Omit); void GetEntries(nsTArray<InternalHeaders::Entry>& aEntries) const; diff --git a/dom/fetch/InternalResponse.cpp b/dom/fetch/InternalResponse.cpp index d99df3d7dc..ec32c4e216 100644 --- a/dom/fetch/InternalResponse.cpp +++ b/dom/fetch/InternalResponse.cpp @@ -17,12 +17,15 @@ namespace mozilla { namespace dom { -InternalResponse::InternalResponse(uint16_t aStatus, const nsACString& aStatusText) +InternalResponse::InternalResponse(uint16_t aStatus, + const nsACString& aStatusText, + RequestCredentials aCredentialsMode) : mType(ResponseType::Default) , mStatus(aStatus) , mStatusText(aStatusText) , mHeaders(new InternalHeaders(HeadersGuardEnum::Response)) , mBodySize(UNKNOWN_BODY_SIZE) + , mCredentialsMode(aCredentialsMode) { } @@ -183,7 +186,7 @@ InternalResponse::CORSResponse() MOZ_ASSERT(!mWrappedResponse, "Can't CORSResponse a already wrapped response"); RefPtr<InternalResponse> cors = CreateIncompleteCopy(); cors->mType = ResponseType::Cors; - cors->mHeaders = InternalHeaders::CORSHeaders(Headers()); + cors->mHeaders = InternalHeaders::CORSHeaders(Headers(), mCredentialsMode); cors->mWrappedResponse = this; return cors.forget(); } diff --git a/dom/fetch/InternalResponse.h b/dom/fetch/InternalResponse.h index 1e282e8abb..e4b4a0ab62 100644 --- a/dom/fetch/InternalResponse.h +++ b/dom/fetch/InternalResponse.h @@ -9,9 +9,10 @@ #include "nsIInputStream.h" #include "nsISupportsImpl.h" +#include "mozilla/dom/InternalHeaders.h" +#include "mozilla/dom/RequestBinding.h" #include "mozilla/dom/ResponseBinding.h" #include "mozilla/dom/ChannelInfo.h" -#include "mozilla/dom/InternalHeaders.h" #include "mozilla/UniquePtr.h" namespace mozilla { @@ -32,7 +33,9 @@ class InternalResponse final public: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(InternalResponse) - InternalResponse(uint16_t aStatus, const nsACString& aStatusText); + InternalResponse(uint16_t aStatus, + const nsACString& aStatusText, + RequestCredentials aCredentialsMode = RequestCredentials::Omit); static already_AddRefed<InternalResponse> FromIPC(const IPCInternalResponse& aIPCResponse); @@ -294,8 +297,11 @@ private: RefPtr<InternalHeaders> mHeaders; nsCOMPtr<nsIInputStream> mBody; int64_t mBodySize; + RequestCredentials mCredentialsMode; + public: static const int64_t UNKNOWN_BODY_SIZE = -1; + private: ChannelInfo mChannelInfo; UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo; |