browser(firefox): preserve content-type from original request if it i… (#16739)

This commit is contained in:
Yury Semikhatsky 2022-08-23 08:51:09 -07:00 committed by GitHub
parent ff46d8ce8a
commit a8249163d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 10 deletions

View File

@ -1,2 +1,2 @@
1347
Changed: aslushnikov@gmail.com Sat Aug 13 14:56:35 MSK 2022
1348
Changed: yurys@chromium.org Mon Aug 22 16:59:01 PDT 2022

View File

@ -863,7 +863,7 @@ function setPostData(httpChannel, postData, headers) {
const body = atob(postData);
synthesized.setData(body, body.length);
const overriddenHeader = (lowerCaseName, defaultValue) => {
const overriddenHeader = (lowerCaseName) => {
if (headers) {
for (const header of headers) {
if (header.name.toLowerCase() === lowerCaseName) {
@ -871,11 +871,22 @@ function setPostData(httpChannel, postData, headers) {
}
}
}
return defaultValue;
return undefined;
}
// Clear content-length, so that upload stream resets it.
httpChannel.setRequestHeader('content-length', '', false /* merge */);
httpChannel.explicitSetUploadStream(synthesized, overriddenHeader('content-type', 'application/octet-stream'), -1, httpChannel.requestMethod, false);
let contentType = overriddenHeader('content-type');
if (contentType === undefined) {
try {
contentType = httpChannel.getRequestHeader('content-type');
} catch (e) {
if (e.result == Cr.NS_ERROR_NOT_AVAILABLE)
contentType = 'application/octet-stream';
else
throw e;
}
}
httpChannel.explicitSetUploadStream(synthesized, contentType, -1, httpChannel.requestMethod, false);
}
function convertString(s, source, dest) {

View File

@ -1,2 +1,2 @@
1345
Changed: aslushnikov@gmail.com Sat Aug 13 14:45:35 MSK 2022
1346
Changed: yurys@chromium.org Mon Aug 22 16:56:24 PDT 2022

View File

@ -863,7 +863,7 @@ function setPostData(httpChannel, postData, headers) {
const body = atob(postData);
synthesized.setData(body, body.length);
const overriddenHeader = (lowerCaseName, defaultValue) => {
const overriddenHeader = (lowerCaseName) => {
if (headers) {
for (const header of headers) {
if (header.name.toLowerCase() === lowerCaseName) {
@ -871,11 +871,22 @@ function setPostData(httpChannel, postData, headers) {
}
}
}
return defaultValue;
return undefined;
}
// Clear content-length, so that upload stream resets it.
httpChannel.setRequestHeader('content-length', '', false /* merge */);
httpChannel.explicitSetUploadStream(synthesized, overriddenHeader('content-type', 'application/octet-stream'), -1, httpChannel.requestMethod, false);
let contentType = overriddenHeader('content-type');
if (contentType === undefined) {
try {
contentType = httpChannel.getRequestHeader('content-type');
} catch (e) {
if (e.result == Cr.NS_ERROR_NOT_AVAILABLE)
contentType = 'application/octet-stream';
else
throw e;
}
}
httpChannel.explicitSetUploadStream(synthesized, contentType, -1, httpChannel.requestMethod, false);
}
function convertString(s, source, dest) {