Merge remote-tracking branch 'origin/tracking' into custom

This commit is contained in:
roytam1 2024-10-31 21:48:26 +08:00
commit 4397f384a7
6 changed files with 83 additions and 16 deletions

View file

@ -644,6 +644,7 @@ nsMultiMixedConv::OnDataAvailable(nsIRequest *request, nsISupports *context,
mContentType.Truncate();
mContentLength = UINT64_MAX;
mContentDisposition.Truncate();
mContentSecurityPolicy.Truncate();
mIsByteRangeRequest = false;
mByteRangeStart = 0;
mByteRangeEnd = 0;
@ -715,6 +716,18 @@ nsMultiMixedConv::OnStartRequest(nsIRequest *request, nsISupports *ctxt) {
if (NS_FAILED(rv)) {
return rv;
}
nsCString csp;
rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("content-security-policy"),
csp);
if (NS_SUCCEEDED(rv)) {
mRootContentSecurityPolicy = csp;
}
nsCString contentDisposition;
rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("content-disposition"),
contentDisposition);
if (NS_SUCCEEDED(rv)) {
mRootContentDisposition = contentDisposition;
}
} else {
// try asking the channel directly
rv = channel->GetContentType(delimiter);
@ -875,7 +888,12 @@ nsMultiMixedConv::SendStart(nsIChannel *aChannel) {
rv = mPartChannel->SetContentLength(mContentLength);
if (NS_FAILED(rv)) return rv;
mPartChannel->SetContentDisposition(mContentDisposition);
// Adopt content-disposition from the root doc, if present.
if (!mRootContentDisposition.IsEmpty()) {
mPartChannel->SetContentDisposition(mRootContentDisposition);
} else {
mPartChannel->SetContentDisposition(mContentDisposition);
}
nsLoadFlags loadFlags = 0;
mPartChannel->GetLoadFlags(&loadFlags);
@ -1062,6 +1080,28 @@ nsMultiMixedConv::ParseHeaders(nsIChannel *aChannel, char *&aPtr,
mIsByteRangeRequest = true;
if (mContentLength == UINT64_MAX)
mContentLength = uint64_t(mByteRangeEnd - mByteRangeStart + 1);
} else if (headerStr.LowerCaseEqualsLiteral("content-security-policy")) {
mContentSecurityPolicy = headerVal;
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
nsCString resultCSP = mRootContentSecurityPolicy;
if (!mContentSecurityPolicy.IsEmpty()) {
// We are updating the root channel CSP header respectively for
// each part as: CSP-root + CSP-partN, where N is the part number.
// Here we append current part's CSP to root CSP and reset CSP
// header for each part.
if (!resultCSP.IsEmpty()) {
resultCSP.Append(";");
}
resultCSP.Append(mContentSecurityPolicy);
}
nsresult rv = httpChannel->SetResponseHeader(
NS_LITERAL_CSTRING("Content-Security-Policy"),
resultCSP, false);
if (NS_FAILED(rv)) {
return NS_ERROR_CORRUPTED_CONTENT;
}
}
}
}
*newLine = tmpChar;

View file

@ -96,7 +96,7 @@ protected:
// main stream and sending them off the destination stream listener, than doing any real
// stream parsing/converting.
//
// WARNING: This converter requires that it's destination stream listener be able to handle
// WARNING: This converter requires that its destination stream listener be able to handle
// multiple OnStartRequest(), OnDataAvailable(), and OnStopRequest() call combinations.
// Each series represents the beginning, data production, and ending phase of each sub-
// part of the original stream.
@ -156,6 +156,9 @@ protected:
nsCOMPtr<nsISupports> mContext;
nsCString mContentType;
nsCString mContentDisposition;
nsCString mContentSecurityPolicy;
nsCString mRootContentSecurityPolicy;
nsCString mRootContentDisposition;
uint64_t mContentLength;
char *mBuffer;