edrlab / thorium-reader

A cross platform desktop reading app, based on the Readium Desktop toolkit
https://www.edrlab.org/software/thorium-reader/
BSD 3-Clause "New" or "Revised" License
1.85k stars 157 forks source link

Downloader : Incorrect download filename from HTTPS content-disposition Header. #2664

Closed panaC closed 2 hours ago

panaC commented 2 hours ago
[2]   readium-desktop:main/http fetch URL: https://github.com/IDPF/epub3-samples/releases/download/20230704/trees.epub +23s
[2]   readium-desktop:main/http Response URL: https://objects.githubusercontent.com/github-production-release-asset-2e65be/30758507/06dfb9af-655e-42e8-bc5f-83ee1d9e3019?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20241118%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241118T172025Z&X-Amz-Expires=300&X-Amz-Signature=151c4444b78f9635172ca4884cc63a33bd14370da70f7f00953ce9a6fa1b5dcd&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Dtrees.epub&response-content-type=application%2Foctet-stream +0ms
[2]   readium-desktop:main/http Method get +0ms
[2]   readium-desktop:main/http Request headers : +0ms
[2]   readium-desktop:main/http {
[2]   readium-desktop:main/http   'accept-language': 'fr,en-US;q=0.7,en;q=0.5',
[2]   readium-desktop:main/http   'user-agent': 'readium-desktop'
[2]   readium-desktop:main/http } +0ms
[2]   readium-desktop:main/http ### +1ms
[2]   readium-desktop:main/http OK:  true +0ms
[2]   readium-desktop:main/http status code : 200 +0ms
[2]   readium-desktop:main/http status text : OK +0ms
[2]   readium-desktop:main/http Response headers : +0ms
[2]   readium-desktop:main/http {
[2]   readium-desktop:main/http   'accept-ranges': [ 'bytes' ],
[2]   readium-desktop:main/http   age: [ '2755' ],
[2]   readium-desktop:main/http   connection: [ 'close' ],
[2]   readium-desktop:main/http   'content-disposition': [ 'attachment; filename=trees.epub' ],
[2]   readium-desktop:main/http   'content-length': [ '75717' ],
[2]   readium-desktop:main/http   'content-type': [ 'application/octet-stream' ],
[2]   readium-desktop:main/http   date: [ 'Mon, 18 Nov 2024 17:20:26 GMT' ],
[2]   readium-desktop:main/http   etag: [ '"0x8DB7CA7E7ADD2AF"' ],
[2]   readium-desktop:main/http   'fastly-restarts': [ '1' ],
[2]   readium-desktop:main/http   'last-modified': [ 'Tue, 04 Jul 2023 16:01:19 GMT' ],
[2]   readium-desktop:main/http   server: [ 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0' ],
[2]   readium-desktop:main/http   via: [ '1.1 varnish, 1.1 varnish' ],
[2]   readium-desktop:main/http   'x-cache': [ 'HIT, HIT' ],
[2]   readium-desktop:main/http   'x-cache-hits': [ '0, 1' ],
[2]   readium-desktop:main/http   'x-ms-blob-content-md5': [ 'RKuAkQ1A3bin4I1zgAegEQ==' ],
[2]   readium-desktop:main/http   'x-ms-blob-type': [ 'BlockBlob' ],
[2]   readium-desktop:main/http   'x-ms-creation-time': [ 'Tue, 04 Jul 2023 16:01:19 GMT' ],
[2]   readium-desktop:main/http   'x-ms-lease-state': [ 'available' ],
[2]   readium-desktop:main/http   'x-ms-lease-status': [ 'unlocked' ],
[2]   readium-desktop:main/http   'x-ms-request-id': [ 'aaaabf70-b01e-004d-6c7e-352eb9000000' ],
[2]   readium-desktop:main/http   'x-ms-server-encrypted': [ 'true' ],
[2]   readium-desktop:main/http   'x-ms-version': [ '2024-08-04' ],
[2]   readium-desktop:main/http   'x-served-by': [ 'cache-iad-kiad7000140-IAD, cache-par-lfpg1960093-PAR' ],
[2]   readium-desktop:main/http   'x-timer': [ 'S1731950426.820238,VS0,VE1' ]
[2]   readium-desktop:main/http } +0ms
[2]   readium-desktop:main/http ### +1ms
[2]   readium-desktop:main#saga/downloader start to stream download +400ms
[2]   readium-desktop:main#saga/downloader Filename file.bin +1ms
[2]   readium-desktop:main#saga/downloader PathFile /var/folders/yq/05l44ygd71vcsw2bwvnjkxw80000gn/T/thorium/download/1731950425705/file.bin +4ms
[2]   readium-desktop:main#saga/downloader PathFile /var/folders/yq/05l44ygd71vcsw2bwvnjkxw80000gn/T/thorium/download/1731950425705/file.bin +0ms
[2]   readium-desktop:main#saga/downloader downloaderService finally +1ms
[2]   readium-desktop:main#saga/downloader ReadStream end _ +2ms
[2]   readium-desktop:main#saga/downloader ReadStream end +0ms
[2]   readium-desktop:main#saga/downloader ReadStream close _ +0ms
[2]   readium-desktop:main#saga/downloader ReadStream close +0ms
[2]   readium-desktop:main#saga/downloader WriteStream finish +0ms
[2]   readium-desktop:main#saga/downloader pipeline done +0ms
[2]   readium-desktop:main#saga/downloader downloaderService filesPath: [
[2]   '/var/folders/yq/05l44ygd71vcsw2bwvnjkxw80000gn/T/thorium/download/1731950425705/file.bin'
[2] ] +0ms
[2]   readium-desktop:main#saga/downloader filePath Array to return from downloader [
[2]   '/var/folders/yq/05l44ygd71vcsw2bwvnjkxw80000gn/T/thorium/download/1731950425705/file.bin'
[2] ] +0ms
[2]   readium-desktop:main#saga/downloader download service closed for 1731950425705 https://github.com/IDPF/epub3-samples/releases/download/20230704/trees.epub +0ms

https://github.com/edrlab/thorium-reader/blob/b5d1e740d995c1317caec3c31b17daba386e2bd9/src/main/redux/sagas/downloader.ts#L285

https://github.com/edrlab/thorium-reader/blob/b5d1e740d995c1317caec3c31b17daba386e2bd9/src/main/redux/sagas/downloader.ts#L302-L309

content-type has the priority https://github.com/edrlab/thorium-reader/blob/b5d1e740d995c1317caec3c31b17daba386e2bd9/src/main/redux/sagas/downloader.ts#L299

danielweck commented 2 hours ago

content-type hhtp header takes precedence (file.bin)

https://github.com/edrlab/thorium-reader/blob/b5d1e740d995c1317caec3c31b17daba386e2bd9/src%2Fmain%2Fredux%2Fsagas%2Fdownloader.ts#L299