browser(firefox): allow to override content-type along with post data (#4416)

This commit is contained in:
Yury Semikhatsky 2020-11-12 10:41:49 -08:00 committed by GitHub
parent eee82a7fca
commit 8488c296f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -1,2 +1,2 @@
1205
Changed: dgozman@gmail.com Sun Nov 8 07:09:21 PST 2020
1206
Changed: yurys@chromium.org Thu 12 Nov 2020 10:23:24 AM PST

View File

@ -238,9 +238,20 @@ class NetworkRequest {
const synthesized = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
const body = atob(postData);
synthesized.setData(body, body.length);
const overridenHeader = (lowerCaseName, defaultValue) => {
if (headers) {
for (const header of headers) {
if (header.name.toLowerCase() === lowerCaseName) {
return header.value;
}
}
}
return defaultValue;
}
// Clear content-length, so that upload stream resets it.
this.httpChannel.setRequestHeader('content-length', '', false /* merge */);
this.httpChannel.explicitSetUploadStream(synthesized, 'application/octet-stream', -1, this.httpChannel.requestMethod, false);
this.httpChannel.setRequestHeader('content-length', overridenHeader('content-length', ''), false /* merge */);
this.httpChannel.explicitSetUploadStream(synthesized, overridenHeader('content-type', 'application/octet-stream'), -1, this.httpChannel.requestMethod, false);
}
}