Skip to content

Commit

Permalink
Merge pull request #2 from feedforce/fetch-correct-content-length
Browse files Browse the repository at this point in the history
content-lengthの値が圧縮後のサイズになるケースがあったので、圧縮前のサイズを取得するようにした
  • Loading branch information
azmin8744 authored Dec 27, 2023
2 parents bff1d18 + cf81ffe commit e160e2b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/file_downloader/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ def execute
def fetch_content_length(http, uri)
http.use_ssl = true if uri.port == 443

res = http.head(uri.request_uri)
# net-httpによるリクエスト時のデフォルトのAccept-Encoding は ["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"] だが、
# サーバによって圧縮後の Content-Length を返すケースがあるため、元のサイズを得る目的でHEADリクエストでは無圧縮とする
res = http.head(uri.request_uri, 'accept-encoding' => '')
Status.check(res.code)
header = res.to_hash
header['content-length'][0]
res.content_length
end

def download_file(http, uri, content_length)
Expand Down

0 comments on commit e160e2b

Please sign in to comment.