このユースケースでは、HTTP Range
リクエストが必要です。私は明確にすべき
http://stuff-things.net/2015/05/13/web-scale-http-tail/
:ここで私が配置チュートリアルですその後、レンジ要求を行って、HEADリクエストでサイズを得ることの利点は、あなたがすべてのコンテンツを転送する必要がないことです。あなたは非常に大きなファイルのリソースを持って言及したので、これは最善の解決策:)
編集になるだろう:以下のコードを追加しました...ここで
が、そのブログ記事のデモ(簡体字)ですが、 Pythonに翻訳されています。これはすべてのHTTPサーバーでは機能しませんのでご注意ください!より多くのコメントをインライン:
正しい答えであるように思わ
"""
illustration of how to 'tail' a file using http. this will not work on all
webservers! if you need an http server to test with you can try the
rangehttpserver module:
$ pip install requests
$ pip install rangehttpserver
$ python -m RangeHTTPServer
"""
import requests
TAIL_SIZE = 1024
url = 'http://localhost:8000/lorem-ipsum.txt'
response = requests.head(url)
# not all servers return content-length in head, for some reason
assert 'content-length' in response.headers, 'Content length unknown- out of luck!'
# check the the resource length and construct a request header for that range
full_length = int(response.headers['content-length'])
assert full_length > TAIL_SIZE
headers = {
'range': 'bytes={}-{}'.format(full_length - TAIL_SIZE, full_length)
}
# Make a get request, with the range header
response = requests.get(url, headers=headers)
assert 'accept-ranges' in response.headers, 'Accept-ranges response header missing'
assert response.headers['accept-ranges'] == 'bytes'
assert len(response.text) == TAIL_SIZE
# Otherwise you get the entire file
response = requests.get(url)
assert len(response.text) == full_length
、しかし、あなたがコピーしてください/リンクのみの答えは(今までのリンク腐朽のことを聞いた)/ downvotedフラグを付ける傾向があるため、作業スニペットを作成します。 –
BTW私はこれらのことについて全く専門家ではありませんが、そのような要求を受け入れないウェブサイトはありません(99%のgrrrrrであっても、すべてのダウンロードをやり直す必要があるサイトなどの古いサイト:) )? –
@ Jean-FrançoisFabreポインタをありがとう!この例をPythonコードに変換しようとします。 (どの言語がとにかくですか?)私はかなりHTTP HeadリクエストとRangeヘッダーがかなり標準的で、かなり普遍的でなければならないと確信しています。しかし、私はhttpサーバにも権限がありません。 –