Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for an issue that matches the one I want to file, without success.
Issue Details
-
Electron Version:
- All
-
Operating System:
- All
-
Last Known Working Electron version:
- Unknown
Expected Behavior
If the filename encoded other than UTF-8 in http header, the filename in Content-disposition should be returned correctly after webRequest.onHeadersReceived is called.
Actual Behavior
If the filename in content-disposition encoded in GBK, before passing the http header to js, the head is converted in UTF-8 instead of doing converting code by charset. Therefore, when callback return, the filename become chaos.
To Reproduce
When visiting a url, server responds a http header:
0x0000: 4854 5450 2f31 2e31 2032 3030 0041 6363 HTTP/1.1.200.Acc
0x0010: 6573 732d 436f 6e74 726f 6c2d 416c 6c6f ess-Control-Allo
0x0020: 772d 4f72 6967 696e 3a20 272a 2700 4163 w-Origin:.'*'.Ac
0x0030: 6365 7373 2d43 6f6e 7472 6f6c 2d41 6c6c cess-Control-All
0x0040: 6f77 2d4d 6574 686f 6473 3a20 504f 5354 ow-Methods:.POST
0x0050: 2c20 4745 542c 204f 5054 494f 4e53 0041 ,.GET,.OPTIONS.A
0x0060: 6363 6573 732d 436f 6e74 726f 6c2d 416c ccess-Control-Al
0x0070: 6c6f 772d 4865 6164 6572 733a 206f 7269 low-Headers:.ori
0x0080: 6769 6e2c 2078 2d63 7372 6674 6f6b 656e gin,.x-csrftoken
0x0090: 2c20 636f 6e74 656e 742d 7479 7065 2c20 ,.content-type,.
0x00a0: 6163 6365 7074 0058 2d41 7070 6c69 6361 accept.X-Applica
0x00b0: 7469 6f6e 2d43 6f6e 7465 7874 3a20 6170 tion-Context:.ap
0x00c0: 706c 6963 6174 696f 6e3a 6465 7665 6c6f plication:develo
0x00d0: 706d 656e 743a 3830 3837 0043 6f6e 7465 pment:8087.Conte
0x00e0: 6e74 2d64 6973 706f 7369 7469 6f6e 3a20 nt-disposition:.
0x00f0: 6174 7461 6368 6d65 6e74 3b20 6669 6c65 attachment;.file
0x0100: 6e61 6d65 3dcc eccc ecd5 e2d1 f95f 5f32 name=........__2
0x0110: 3032 3030 3932 345f 3034 3232 3533 3200 0200924_0422532.
0x0120: 436f 6e74 656e 742d 5479 7065 3a20 6170 Content-Type:.ap
0x0130: 706c 6963 6174 696f 6e2f 6f63 7465 742d plication/octet-
0x0140: 7374 7265 616d 0054 7261 6e73 6665 722d stream.Transfer-
0x0150: 456e 636f 6469 6e67 3a20 6368 756e 6b65 Encoding:.chunke
0x0160: 6400 4461 7465 3a20 5468 752c 2032 3420 d.Date:.Thu,.24.
0x0170: 5365 7020 3230 3230 2030 383a 3232 3a31 Sep.2020.08:22:1
0x0180: 3720 474d 5400 00 7.GMT..
When the onHeadersReceived is regitered, like the following:
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
callback({
cancel: false,
responseHeaders: details.responseHeaders,
statusLine: details.statusLine,
});
});
Then, the response header has been change to:
0x0000: 4854 5450 2f31 2e31 2032 3030 0041 6363 HTTP/1.1.200.Acc
0x0010: 6573 732d 436f 6e74 726f 6c2d 416c 6c6f ess-Control-Allo
0x0020: 772d 4865 6164 6572 733a 206f 7269 6769 w-Headers:.origi
0x0030: 6e2c 2078 2d63 7372 6674 6f6b 656e 2c20 n,.x-csrftoken,.
0x0040: 636f 6e74 656e 742d 7479 7065 2c20 6163 content-type,.ac
0x0050: 6365 7074 0041 6363 6573 732d 436f 6e74 cept.Access-Cont
0x0060: 726f 6c2d 416c 6c6f 772d 4d65 7468 6f64 rol-Allow-Method
0x0070: 733a 2050 4f53 542c 2047 4554 2c20 4f50 s:.POST,.GET,.OP
0x0080: 5449 4f4e 5300 4163 6365 7373 2d43 6f6e TIONS.Access-Con
0x0090: 7472 6f6c 2d41 6c6c 6f77 2d4f 7269 6769 trol-Allow-Origi
0x00a0: 6e3a 2027 2a27 0043 6f6e 7465 6e74 2d54 n:.'*'.Content-T
0x00b0: 7970 653a 2061 7070 6c69 6361 7469 6f6e ype:.application
0x00c0: 2f6f 6374 6574 2d73 7472 6561 6d00 436f /octet-stream.Co
0x00d0: 6e74 656e 742d 6469 7370 6f73 6974 696f ntent-dispositio
0x00e0: 6e3a 2061 7474 6163 686d 656e 743b 2066 n:.attachment;.f
0x00f0: 696c 656e 616d 653d efbf bdef bfbd efbf ilename=........
0x0100: bdef bfbd efbf bdef bfbd efbf bdef bfbd ................
0x0110: 5f5f 3230 3230 3039 3234 5f30 3432 3235 __20200924_04225
0x0120: 3332 0044 6174 653a 2054 6875 2c20 3234 32.Date:.Thu,.24
0x0130: 2053 6570 2032 3032 3020 3038 3a32 323a .Sep.2020.08:22:
0x0140: 3137 2047 4d54 0054 7261 6e73 6665 722d 17.GMT.Transfer-
0x0150: 456e 636f 6469 6e67 3a20 6368 756e 6b65 Encoding:.chunke
0x0160: 6400 582d 4170 706c 6963 6174 696f 6e2d d.X-Application-
0x0170: 436f 6e74 6578 743a 2061 7070 6c69 6361 Context:.applica
0x0180: 7469 6f6e 3a64 6576 656c 6f70 6d65 6e74 tion:development
0x0190: 3a38 3038 3700 00 :8087..
The original filename in Content-disposition has been lost forever.
Additional Information
I've investigated the reason. It is because the call
gin::ConvertToV8(v8::Isolate::GetCurrent(), response_headers);
on the function HttpResponseHeadersToV8
in the source file electron_api_web_request.cc.