HTTP/1.1 response to multiple range

自作多情 提交于 2020-01-12 14:23:18

问题


While writing my HTTP/1.1 server, I get stuck dealing multiple ranges request.

Section 14.35.1 of RFC 2616 refers some examples but doesn't clarify server behaviour. For instance:

GET /some/resource HTTP/1.1
...
Range: bytes=200-400,100-300,500-600
...

Should I return this exact sequence of bytes? Or should I merge all ranges, sending 100-400,500-600? Or sending all in between, 100-600?

Worst, when checking Content-Range response header (Section 14.16), only a single range may be returned, so I wonder how would a server response to example in Section 14.35.1 bytes=0-0,-1!!!

How should my server handle such requests?


回答1:


I just had a look at how other servers that support the Range header field might respond and did a quick curl to example.com:

~# curl -s -D - -H "Range: bytes=100-200, 300-400" http://www.example.com
HTTP/1.1 206 Partial Content
Accept-Ranges: bytes
Content-Type: multipart/byteranges; boundary=3d6b6a416f9b5
Content-Length: 385
Server: ECS (fll/0761)


--3d6b6a416f9b5
Content-Type: text/html
Content-Range: bytes 100-200/1270

eta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="vieport" content
--3d6b6a416f9b5
Content-Type: text/html
Content-Range: bytes 300-400/1270

-color: #f0f0f2;
        margin: 0;
        padding: 0;
        font-family: "Open Sans", "Helvetica
--3d6b6a416f9b5--

Apparently, what your looking for is the Content-Type: multipart/byteranges; boundary response header. Googling exactly that turned up a W3C document with appendices to RFC 2616

When an HTTP 206 (Partial Content) response message includes the content of multiple ranges (a response to a request for multiple non-overlapping ranges), these are transmitted as a multipart message-body. The media type for this purpose is called "multipart/byteranges".
The multipart/byteranges media type includes two or more parts, each with its own Content-Type and Content-Range fields. The required boundary parameter specifies the boundary string used to separate each body-part.

So there you go.

By the way, the server at example.com does not check for overlapping byte ranges and sends you exactly the ranges that you requested...



来源:https://stackoverflow.com/questions/18315787/http-1-1-response-to-multiple-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!