Skip to content

Commit

Permalink
fix: restore Chromium default Content-Disposition header parsing (#…
Browse files Browse the repository at this point in the history
…43668)

* fix: restore Chromium default Content-Disposition header parsing

Co-authored-by: Milan Burda <[email protected]>

* Update api-web-request-spec.ts

Co-authored-by: Milan Burda <[email protected]>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Milan Burda <[email protected]>
  • Loading branch information
trop[bot] and miniak authored Sep 10, 2024
1 parent 7034537 commit 017ba5b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
17 changes: 0 additions & 17 deletions shell/browser/api/electron_api_web_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -98,22 +97,6 @@ v8::Local<v8::Value> 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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion spec/api-web-request-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 017ba5b

Please sign in to comment.