8

What is the correct response to a GET request with the header field Range: bytes=278528- if Range is not supported?

Reading the HTTP header definitions (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) i think i should at least set: Accept-Ranges: none, but it clearly states that

Clients MAY generate byte-range requests without having received this header for the resource involved.

So, if a client requests a range, should I:

user9876
  • 10,954
  • 6
  • 44
  • 66
Joernsn
  • 2,319
  • 4
  • 25
  • 33

4 Answers4

10

You may ignore it, as the spec says. To be precise:

  • If you support it, you return a status code of 206 Partial Content and include the proper headers like Content-Range.
  • If you don’t support it, you return a 200 OK as normal.

I have not tested this, but the spec seems pretty clear. I have seen this work — using wget or curl to resume an interrupted download will properly restart from the beginning if the server does not support the Range header.

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
  • 2
    Too bad the client also ignores me ignoring it. Android's MediaPlayer on LG/Motorola phones (OMXPlayer) crashes if you return a 200 with full body :( – Joernsn Jun 01 '11 at 19:31
  • Such a client is just bad. Per HTTP spec that should be okay. – Mikko Rantalainen Dec 10 '20 at 14:15
  • Basically, if the feature is supported, THEN the response code is 206 and the response contains HTTP header `Content-Range` with info about the bytes included in the response. If the feature is not supported, response code is *anything* else but 206 and the response doesn't include `Content-Range` header. – Mikko Rantalainen Dec 10 '20 at 14:17
  • Note that e.g. Safari doesn't play – Mikko Rantalainen Dec 10 '20 at 14:18
5

RFC2616 section 14.35.2 says:

A server MAY ignore the Range header.

Nemo
  • 70,042
  • 10
  • 116
  • 153
1

The possibility is check the http header and if there is a range string, parse it, parse to ranges, compute skip and take positions, open file stream from url, then, seek to skip and take 'take ' bytes, setup response of it, send response and finaly close stream. do not forget to respond with range header

do not ignore range, never when you are working on big streams.

if you are using nanohttp, i can help you out with example

Milan Jurkulak
  • 557
  • 3
  • 6
0

Ignoring range requests can made play content (which is huge) on airplay service or another unstable or unacceptable. I know that http is not right protokol to transfer video, but try to send video to airplay from server not accepting ranges.... Airplay uses range requests...

Milan Jurkulak
  • 557
  • 3
  • 6