1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00
pdf.js/src
Andrii Vitiv 824a619a2a
Fix error on empty response headers
Fixes https://github.com/mozilla/pdf.js/issues/18957

https://github.com/mozilla/pdf.js/pull/18682 introduced a regression that causes the following error:

```
Uncaught TypeError: Failed to construct 'Headers': Invalid name
    at PDFNetworkStreamFullRequestReader._onHeadersReceived (pdf.mjs:10214:29)
    at NetworkManager.onStateChange (pdf.mjs:10103:22)
```

The mentioned PR replaced a call to `getResponseHeader()` with `getAllResponseHeaders()` without handling cases where it may return null or an empty string. Quote from the [docs](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#return_value):

> Returns:
>
>A string representing all of the response's headers (except those whose field name is Set-Cookie) separated by CRLF, or null if no response has been received. If a network error happened, an empty string is returned.

Run the following code and observe the error in the console. Note that the URL is intentionally set to an invalid value to simulate network error

```js
<script src="//mozilla.github.io/pdf.js/build/pdf.mjs" type="module"></script>

<script type="module">
  var url = 'blob:';

  pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.mjs';

  var loadingTask = pdfjsLib.getDocument(url);
  loadingTask.promise
    .then((pdf) => console.log('PDF loaded'))
    .catch((reason) => console.error(reason));

</script>
```
2024-11-05 21:52:50 +02:00
..
core Merge pull request #18992 from Snuffleupagus/getPdfManager-inline-flushChunks 2024-11-02 18:58:29 +01:00
display Fix error on empty response headers 2024-11-05 21:52:50 +02:00
images Vectorize the logo. 2012-10-29 14:08:52 -04:00
scripting_api Make util.scand a bit more flexible with dates which don't match the given format (bug 1910431) 2024-10-27 19:19:06 +01:00
shared Use the hexNumbers structure in the stringToUTF16HexString helper 2024-11-02 15:00:32 +01:00
interfaces.js Use ESLint to ensure that exports are sorted alphabetically 2021-01-09 20:37:51 +01:00
license_header.js Update the year in the license_header files 2024-07-02 14:34:59 +02:00
license_header_libre.js Update the year in the license_header files 2024-07-02 14:34:59 +02:00
pdf.image_decoders.js [api-minor] Remove the image-related error message prefixes 2024-04-20 12:51:45 +02:00
pdf.js Move the various DOM-factories into their own files 2024-11-01 13:31:28 +01:00
pdf.sandbox.external.js Avoid to call a function in the js sandbox when it has been destroyed 2024-06-18 22:30:21 +02:00
pdf.sandbox.js Use shorter arrow functions where possible 2024-01-21 10:13:12 +01:00
pdf.scripting.js Output pdf.scripting.js as a JavaScript module (PR 17055 follow-up) 2023-10-07 15:27:26 +02:00
pdf.worker.js Allow, optionally, using worker-modules during local development 2023-01-31 12:09:44 +01:00