HTTP 範囲リクエスト

This translation is incomplete. この記事の翻訳にご協力ください

HTTP 範囲リクエストでは、サーバーからクライアントに HTTP メッセージの一部のみを送信できます。部分リクエストは、たとえば、大きなメディアや、一時停止や再開機能を持つファイルのダウンロードに役立ちます。


Accept-Ranges が HTTP レスポンスに存在した場合 (そして値が "none" ではない場合)、サーバーは範囲リクエストに対応しています。これは例えば、 HEAD リクエストを cURL で発行することで確認することができます。

curl -I

HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 146515

このレスポンスの中で、 Accept-Ranges: bytes は範囲を定義する単位としてバイト数が使えることを示しています。ここで Content-Length ヘッダーも受け取る画像の全体の長さを示すので有用です。

サイトが Accept-Ranges ヘッダーを省略した場合は、おそらく部分リクエストに対応していません。サイトにとっては値として明示的に "none" を送信して、対応がないことを示すこともあります。アプリによっては、このような場合にダウンロードマネージャーが一時停止ボタンを無効化します。

curl -I

HTTP/1.1 200 OK
Accept-Ranges: none


If the server supports range requests, you can issue such a request by using the Range header. It indicates the part(s) of a document that the server should return.


We can request a single range from a resource. Again, we can test a request by using cURL. The "-H" option will append a header line to the request, which in this case is the Range header requesting the first 1024 bytes.

curl -i -H "Range: bytes=0-1023"

The issued request looks like this:

GET /z4d4kWk.jpg HTTP/1.1
Range: bytes=0-1023

The server responses with the 206 Partial Content status:

HTTP/1.1 206 Partial Content
Content-Range: bytes 0-1023/146515
Content-Length: 1024
(binary content)

The Content-Length header now indicates the size of the requested range (and not the full size of the image). The Content-Range response header indicates where in the full resource this partial message belongs.


The Range header also allows you to get multiple ranges at once in a multipart document. The ranges are separated by a comma.

curl -i -H "Range: bytes=0-50, 100-150"

The server responses with the 206 Partial Content status and a Content-Type: multipart/byteranges; boundary=3d6b6a416f9b5 header, indicating that a multipart byterange follows. Each part contains its own Content-Type and Content-Range fields and the required boundary parameter specifies the boundary string used to separate each body-part.

HTTP/1.1 206 Partial Content
Content-Type: multipart/byteranges; boundary=3d6b6a416f9b5
Content-Length: 282

Content-Type: text/html
Content-Range: bytes 0-50/1270

<!doctype html>
    <title>Example Do
Content-Type: text/html
Content-Range: bytes 100-150/1270

eta http-equiv="Content-type" content="text/html; c


When resuming to request more parts of a resource, you need to guarantee that the stored resource has not been modified since the last fragment has been received.

The If-Range HTTP request header makes a range request conditional: if the condition is fulfilled, the range request will be issued and the server sends back a 206 Partial Content answer with the appropriate body. If the condition is not fulfilled, the full resource is sent back, with a 200 OK status. This header can be used either with a Last-Modified validator, or with an ETag, but not with both.

If-Range: Wed, 21 Oct 2015 07:28:00 GMT 


There are three relevant statuses, when working with range requests:

  • In case of a successful range request, the 206 Partial Content status is sent back from a server.
  • In case of a range request that is out of bounds (range values overlap the extent of the resource), the server responds with a 416 Requested Range Not Satisfiable status.
  • In case of no support of range requests, the 200 OK status is sent back from a server.

チャンク Transfer-Encoding との比較

The Transfer-Encoding header allows chunked encoding, which is useful when larger amounts of data are sent to the client and the total size of the response is not known until the request has been fully processed. The server sends data to the client straight away without buffering the response or determining the exact length, which leads to improved latency. Range requests and chunking are compatible and can be used with or without each other.