зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1638513
- P2 let nsIHttpChannel implement shouldStripRequestBodyHeader, r=valentin,necko-reviewers
We need to extract the common method into the idl since the connection between necko and XHR is idl. Need to import the whole necko if we do something like `#include "HttpBaseChannel.h" Differential Revision: https://phabricator.services.mozilla.com/D78830
This commit is contained in:
Родитель
b7d7ea4350
Коммит
c967db3c67
|
@ -1432,20 +1432,13 @@ FetchDriver::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
|
|||
nsCOMPtr<nsIHttpChannel> oldHttpChannel = do_QueryInterface(aOldChannel);
|
||||
nsCOMPtr<nsIHttpChannel> newHttpChannel = do_QueryInterface(aNewChannel);
|
||||
if (newHttpChannel) {
|
||||
uint32_t responseCode = 0;
|
||||
bool rewriteToGET = false;
|
||||
if (oldHttpChannel &&
|
||||
NS_SUCCEEDED(oldHttpChannel->GetResponseStatus(&responseCode))) {
|
||||
nsAutoCString method;
|
||||
mRequest->GetMethod(method);
|
||||
nsAutoCString method;
|
||||
mRequest->GetMethod(method);
|
||||
|
||||
// Fetch 4.4.11
|
||||
rewriteToGET =
|
||||
((responseCode == 301 || responseCode == 302) &&
|
||||
method.LowerCaseEqualsASCII("post")) ||
|
||||
(responseCode == 303 && !method.LowerCaseEqualsASCII("get") &&
|
||||
!method.LowerCaseEqualsASCII("head"));
|
||||
}
|
||||
// Fetch 4.4.11
|
||||
bool rewriteToGET = false;
|
||||
Unused << oldHttpChannel->ShouldStripRequestBodyHeader(method,
|
||||
&rewriteToGET);
|
||||
|
||||
SetRequestHeaders(newHttpChannel, rewriteToGET);
|
||||
}
|
||||
|
|
|
@ -3324,16 +3324,9 @@ nsresult XMLHttpRequestMainThread::OnRedirectVerifyCallback(nsresult result) {
|
|||
if (NS_SUCCEEDED(result)) {
|
||||
bool rewriteToGET = false;
|
||||
nsCOMPtr<nsIHttpChannel> oldHttpChannel = GetCurrentHttpChannel();
|
||||
if (uint32_t responseCode = 0;
|
||||
oldHttpChannel &&
|
||||
NS_SUCCEEDED(oldHttpChannel->GetResponseStatus(&responseCode))) {
|
||||
// Fetch 4.4.11
|
||||
rewriteToGET =
|
||||
((responseCode == 301 || responseCode == 302) &&
|
||||
mRequestMethod.LowerCaseEqualsASCII("post")) ||
|
||||
(responseCode == 303 && !mRequestMethod.LowerCaseEqualsASCII("get") &&
|
||||
!mRequestMethod.LowerCaseEqualsASCII("head"));
|
||||
}
|
||||
// Fetch 4.4.11
|
||||
Unused << oldHttpChannel->ShouldStripRequestBodyHeader(mRequestMethod,
|
||||
&rewriteToGET);
|
||||
|
||||
mChannel = mNewRedirectChannel;
|
||||
|
||||
|
|
|
@ -3352,6 +3352,27 @@ bool HttpBaseChannel::ShouldRewriteRedirectToGET(
|
|||
return false;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HttpBaseChannel::ShouldStripRequestBodyHeader(const nsACString& aMethod,
|
||||
bool* aResult) {
|
||||
*aResult = false;
|
||||
uint32_t httpStatus = 0;
|
||||
if (NS_FAILED(GetResponseStatus(&httpStatus))) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoCString method(aMethod);
|
||||
nsHttpRequestHead::ParsedMethodType parsedMethod;
|
||||
nsHttpRequestHead::ParseMethod(method, parsedMethod);
|
||||
// Fetch 4.4.11, which is slightly different than the perserved method
|
||||
// algrorithm: strip request-body-header for GET->GET redirection for 303.
|
||||
*aResult =
|
||||
ShouldRewriteRedirectToGET(httpStatus, parsedMethod) &&
|
||||
!(httpStatus == 303 && parsedMethod == nsHttpRequestHead::kMethod_Get);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
HttpBaseChannel::ReplacementChannelConfig
|
||||
HttpBaseChannel::CloneReplacementChannelConfig(bool aPreserveMethod,
|
||||
uint32_t aRedirectFlags,
|
||||
|
|
|
@ -198,6 +198,8 @@ class HttpBaseChannel : public nsHashPropertyBag,
|
|||
NS_IMETHOD VisitRequestHeaders(nsIHttpHeaderVisitor* visitor) override;
|
||||
NS_IMETHOD VisitNonDefaultRequestHeaders(
|
||||
nsIHttpHeaderVisitor* visitor) override;
|
||||
NS_IMETHOD ShouldStripRequestBodyHeader(const nsACString& aMethod,
|
||||
bool* aResult) override;
|
||||
NS_IMETHOD GetResponseHeader(const nsACString& header,
|
||||
nsACString& value) override;
|
||||
NS_IMETHOD SetResponseHeader(const nsACString& header,
|
||||
|
|
|
@ -231,6 +231,12 @@ NullHttpChannel::VisitOriginalResponseHeaders(nsIHttpHeaderVisitor* aVisitor) {
|
|||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
NullHttpChannel::ShouldStripRequestBodyHeader(const nsACString& aMethod,
|
||||
bool* aResult) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
NullHttpChannel::IsNoStoreResponse(bool* _retval) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
|
|
@ -183,6 +183,12 @@ interface nsIHttpChannel : nsIIdentChannel
|
|||
[must_use]
|
||||
void visitNonDefaultRequestHeaders(in nsIHttpHeaderVisitor aVisitor);
|
||||
|
||||
/**
|
||||
* Call this method to see if we need to strip the request body headers
|
||||
* for the new http channel. This should be called during redirection.
|
||||
*/
|
||||
[must_use] bool ShouldStripRequestBodyHeader(in ACString aMethod);
|
||||
|
||||
/**
|
||||
* This attribute no longer has any effect, it remains for backwards compat
|
||||
*
|
||||
|
|
|
@ -827,6 +827,14 @@ nsViewSourceChannel::VisitNonDefaultRequestHeaders(
|
|||
: mHttpChannel->VisitNonDefaultRequestHeaders(aVisitor);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsViewSourceChannel::ShouldStripRequestBodyHeader(const nsACString& aMethod,
|
||||
bool* aResult) {
|
||||
return !mHttpChannel
|
||||
? NS_ERROR_NULL_POINTER
|
||||
: mHttpChannel->ShouldStripRequestBodyHeader(aMethod, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsViewSourceChannel::GetAllowPipelining(bool* aAllowPipelining) {
|
||||
return !mHttpChannel ? NS_ERROR_NULL_POINTER
|
||||
|
|
Загрузка…
Ссылка в новой задаче