fix: restore Chromium default Content-Disposition header parsing (#43670)
		
	* fix: restore Chromium default Content-Disposition header parsing Co-authored-by: Milan Burda <milan.burda@gmail.com> * Update api-web-request-spec.ts Co-authored-by: Milan Burda <milan.burda@gmail.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Milan Burda <milan.burda@gmail.com>
This commit is contained in:
		
					parent
					
						
							
								c7380437aa
							
						
					
				
			
			
				commit
				
					
						87fc32f0aa
					
				
			
		
					 2 changed files with 1 additions and 18 deletions
				
			
		|  | @ -21,7 +21,6 @@ | ||||||
| #include "gin/dictionary.h" | #include "gin/dictionary.h" | ||||||
| #include "gin/handle.h" | #include "gin/handle.h" | ||||||
| #include "gin/object_template_builder.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_session.h" | ||||||
| #include "shell/browser/api/electron_api_web_contents.h" | #include "shell/browser/api/electron_api_web_contents.h" | ||||||
| #include "shell/browser/api/electron_api_web_frame_main.h" | #include "shell/browser/api/electron_api_web_frame_main.h" | ||||||
|  | @ -100,22 +99,6 @@ v8::Local<v8::Value> HttpResponseHeadersToV8( | ||||||
|     std::string key; |     std::string key; | ||||||
|     std::string value; |     std::string value; | ||||||
|     while (headers->EnumerateHeaderLines(&iter, &key, &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); |       response_headers.EnsureList(key)->Append(value); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | @ -474,7 +474,7 @@ describe('webRequest module', () => { | ||||||
| 
 | 
 | ||||||
|     it('does not change content-disposition header by default', async () => { |     it('does not change content-disposition header by default', async () => { | ||||||
|       ses.webRequest.onHeadersReceived((details, callback) => { |       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({}); |         callback({}); | ||||||
|       }); |       }); | ||||||
|       const { data, headers } = await ajax(defaultURL + 'contentDisposition'); |       const { data, headers } = await ajax(defaultURL + 'contentDisposition'); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	![37223003+trop[bot]@users.noreply.github.com](/assets/img/avatar_default.png) trop[bot]
				trop[bot]