mirror of
				https://github.com/godotengine/godot.git
				synced 2025-10-31 13:41:03 +00:00 
			
		
		
		
	[HTML5] Disable body_size in fetch.
We were using `Content-Length` from the server when `Content-Encoding`
was not set (i.e. response was not compressed).
Sadly, in CORS requests accessing headers is restricted, and while
`Content-Length` is enabled by default, `Content-Encoding` is not.
This results in the impossibility of knowing if the content was
compressed, unless the server explicitly enabled the encoding header
via `Access-Control-Expose-Headers`.
To keep maximum compatibility we must disable `body_size` completely.
(cherry picked from commit 737ed0f66e)
			
			
This commit is contained in:
		
							parent
							
								
									1cd13d22c2
								
							
						
					
					
						commit
						f90b24a805
					
				
					 2 changed files with 1 additions and 29 deletions
				
			
		|  | @ -49,25 +49,14 @@ const GodotFetch = { | |||
| 			if (!obj) { | ||||
| 				return; | ||||
| 			} | ||||
| 			let size = -1; | ||||
| 			let compressed = false; | ||||
| 			let chunked = false; | ||||
| 			response.headers.forEach(function (value, header) { | ||||
| 				const v = value.toLowerCase().trim(); | ||||
| 				const h = header.toLowerCase().trim(); | ||||
| 				if (h === 'content-encoding') { | ||||
| 					compressed = true; | ||||
| 					size = -1; | ||||
| 				} else if (h === 'content-length') { | ||||
| 					const len = Number.parseInt(value, 10); | ||||
| 					if (!Number.isNaN(len) && !compressed) { | ||||
| 						size = len; | ||||
| 					} | ||||
| 				} else if (h === 'transfer-encoding' && v === 'chunked') { | ||||
| 				if (h === 'transfer-encoding' && v === 'chunked') { | ||||
| 					chunked = true; | ||||
| 				} | ||||
| 			}); | ||||
| 			obj.bodySize = size; | ||||
| 			obj.status = response.status; | ||||
| 			obj.response = response; | ||||
| 			obj.reader = response.body.getReader(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Fabio Alessandrelli
						Fabio Alessandrelli