Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content-lengthの値が圧縮後のサイズになるケースがあったので、圧縮前のサイズを取得するようにした #2

Merged
merged 1 commit into from
Dec 27, 2023

Conversation

azmin8744
Copy link

このPRでやりたいこと

Content-Lengthの値を正しく取得できるようにしたい。

FileDownloader.download では、ファイルが最後までダウンロードできたか判定するために、ダウンロード前にHEADリクエストを行い、Content-Lengthの値でダウンロードするファイルのサイズを取得している。

HEADリクエストを行う際、 Accept-Encoding に圧縮形式を指定することで、相手先サーバによって Content-Length の値が圧縮後のサイズになる、あるいは Content-Length が返されない場合があることがわかった。

FileDownloaderでは、Content-Lengthの値とファイルシステムに書き込んだサイズを比較して最後までダウンロードできたか判定しているため、 Content-Length は圧縮前のファイルサイズで取得できることが望ましい。

やったこと

FileDownloader::Service#fetch_content_length で HEAD リクエストを行う時に、リクエストヘッダを 'accept-encoding' => '' でオーバーライドした。

@azmin8744 azmin8744 merged commit e160e2b into master Dec 27, 2023
4 checks passed
@azmin8744 azmin8744 deleted the fetch-correct-content-length branch December 27, 2023 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants