From 2c3416627f6c6c1ee2e297aa6c05818d3b50dd47 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Tue, 10 Sep 2024 13:27:22 -0400 Subject: [PATCH] fix: restore Chromium default `Content-Disposition` header parsing (#43669) * fix: restore Chromium default Content-Disposition header parsing Co-authored-by: Milan Burda * Update api-web-request-spec.ts Co-authored-by: Milan Burda --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Milan Burda --- shell/browser/api/electron_api_web_request.cc | 17 ----------------- spec/api-web-request-spec.ts | 2 +- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/shell/browser/api/electron_api_web_request.cc b/shell/browser/api/electron_api_web_request.cc index 0ad852279adf..80515e80dfa9 100644 --- a/shell/browser/api/electron_api_web_request.cc +++ b/shell/browser/api/electron_api_web_request.cc @@ -19,7 +19,6 @@ #include "gin/converter.h" #include "gin/dictionary.h" #include "gin/object_template_builder.h" -#include "net/http/http_content_disposition.h" #include "shell/browser/api/electron_api_session.h" #include "shell/browser/api/electron_api_web_contents.h" #include "shell/browser/api/electron_api_web_frame_main.h" @@ -98,22 +97,6 @@ v8::Local HttpResponseHeadersToV8( std::string key; std::string value; while (headers->EnumerateHeaderLines(&iter, &key, &value)) { - // Note that Web servers not developed with nodejs allow non-utf8 - // characters in content-disposition's filename field. Use Chromium's - // HttpContentDisposition class to decode the correct encoding instead of - // arbitrarily converting it to UTF8. It should also be noted that if the - // encoding is not specified, HttpContentDisposition will transcode - // according to the system's encoding. - if (base::EqualsCaseInsensitiveASCII("Content-Disposition", key) && - !value.empty()) { - net::HttpContentDisposition header(value, std::string()); - std::string decodedFilename = - header.is_attachment() ? " attachment" : " inline"; - // The filename must be encased in double quotes for serialization - // to happen correctly. - std::string filename = "\"" + header.filename() + "\""; - value = decodedFilename + "; filename=" + filename; - } response_headers.EnsureList(key)->Append(value); } } diff --git a/spec/api-web-request-spec.ts b/spec/api-web-request-spec.ts index e57c7a206300..861ffcd25679 100644 --- a/spec/api-web-request-spec.ts +++ b/spec/api-web-request-spec.ts @@ -474,7 +474,7 @@ describe('webRequest module', () => { it('does not change content-disposition header by default', async () => { ses.webRequest.onHeadersReceived((details, callback) => { - expect(details.responseHeaders!['content-disposition']).to.deep.equal([' attachment; filename="aa中aa.txt"']); + expect(details.responseHeaders!['content-disposition']).to.deep.equal(['attachment; filename=aa中aa.txt']); callback({}); }); const { data, headers } = await ajax(defaultURL + 'contentDisposition');