From a8249163d3532fd28fe6645e13e8d6b686811ac0 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 23 Aug 2022 08:51:09 -0700 Subject: [PATCH] =?UTF-8?q?browser(firefox):=20preserve=20content-type=20f?= =?UTF-8?q?rom=20original=20request=20if=20it=20i=E2=80=A6=20(#16739)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- browser_patches/firefox-beta/BUILD_NUMBER | 4 ++-- .../firefox-beta/juggler/NetworkObserver.js | 17 ++++++++++++++--- browser_patches/firefox/BUILD_NUMBER | 4 ++-- .../firefox/juggler/NetworkObserver.js | 17 ++++++++++++++--- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/browser_patches/firefox-beta/BUILD_NUMBER b/browser_patches/firefox-beta/BUILD_NUMBER index 3a5b761627..0c00dc438f 100644 --- a/browser_patches/firefox-beta/BUILD_NUMBER +++ b/browser_patches/firefox-beta/BUILD_NUMBER @@ -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 diff --git a/browser_patches/firefox-beta/juggler/NetworkObserver.js b/browser_patches/firefox-beta/juggler/NetworkObserver.js index 340f756f6c..f197959497 100644 --- a/browser_patches/firefox-beta/juggler/NetworkObserver.js +++ b/browser_patches/firefox-beta/juggler/NetworkObserver.js @@ -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) { diff --git a/browser_patches/firefox/BUILD_NUMBER b/browser_patches/firefox/BUILD_NUMBER index 167b11029d..f892b88a0f 100644 --- a/browser_patches/firefox/BUILD_NUMBER +++ b/browser_patches/firefox/BUILD_NUMBER @@ -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 diff --git a/browser_patches/firefox/juggler/NetworkObserver.js b/browser_patches/firefox/juggler/NetworkObserver.js index 340f756f6c..f197959497 100644 --- a/browser_patches/firefox/juggler/NetworkObserver.js +++ b/browser_patches/firefox/juggler/NetworkObserver.js @@ -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) {