Correctly validate the response status for non-HTTP fetch requests (PR 8768 follow-up)
It seems that the status check, for non-HTTP loads, causes the default viewer to *refuse* to open local PDF files. ***STR:*** 1. Make sure that fetch support is enabled in the browser. In Firefox Nightly, set `dom.streams.enabled = true` and `javascript.options.streams = true` in `about:config`. 2. Open https://mozilla.github.io/pdf.js/web/viewer.html. 3. Click on the "Open file" button, and open a new PDF file. ***ER:*** A new PDF file should open in the viewer. ***AR:*** The PDF file fails to open, with an error message of the following format: `Message: Unexpected server response (200) while retrieving PDF "blob:https://mozilla.github.io/a4fc455f-bc05-45b5-b6aa-2ecff3cb45ce".`
This commit is contained in:
		
							parent
							
								
									cd25a51abe
								
							
						
					
					
						commit
						41415ba0a2
					
				| @ -94,7 +94,7 @@ class PDFFetchStreamReader { | |||||||
|     let url = this._stream.source.url; |     let url = this._stream.source.url; | ||||||
|     fetch(url, createFetchOptions(this._headers, this._withCredentials)). |     fetch(url, createFetchOptions(this._headers, this._withCredentials)). | ||||||
|         then((response) => { |         then((response) => { | ||||||
|       if (!validateResponseStatus(response.status, this._stream.isHttp)) { |       if (!validateResponseStatus(response.status)) { | ||||||
|         throw createResponseStatusError(response.status, url); |         throw createResponseStatusError(response.status, url); | ||||||
|       } |       } | ||||||
|       this._reader = response.body.getReader(); |       this._reader = response.body.getReader(); | ||||||
| @ -188,7 +188,7 @@ class PDFFetchStreamRangeReader { | |||||||
|     let url = this._stream.source.url; |     let url = this._stream.source.url; | ||||||
|     fetch(url, createFetchOptions(this._headers, this._withCredentials)). |     fetch(url, createFetchOptions(this._headers, this._withCredentials)). | ||||||
|         then((response) => { |         then((response) => { | ||||||
|       if (!validateResponseStatus(response.status, this._stream.isHttp)) { |       if (!validateResponseStatus(response.status)) { | ||||||
|         throw createResponseStatusError(response.status, url); |         throw createResponseStatusError(response.status, url); | ||||||
|       } |       } | ||||||
|       this._readCapability.resolve(); |       this._readCapability.resolve(); | ||||||
|  | |||||||
| @ -61,10 +61,7 @@ function createResponseStatusError(status, url) { | |||||||
|     ') while retrieving PDF "' + url + '".', status); |     ') while retrieving PDF "' + url + '".', status); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function validateResponseStatus(status, isHttp) { | function validateResponseStatus(status) { | ||||||
|   if (!isHttp) { |  | ||||||
|     return status === 0; |  | ||||||
|   } |  | ||||||
|   return status === 200 || status === 206; |   return status === 200 || status === 206; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user