I have a server and sometimes when client ask for a file and if its request header Range may get over the length of file, so the server returns 416 status code. But I'm wondering should it write file content too ? or simply return 416 with no content ?

Explaination on W3 Website doesn't clearify enough.

What I understood from the W3 web, that it should write Content-Range header(starting with 0?). So if content length is 10 bytes. The response should look like

HTTP/1.1 416
Content-Range: bytes 0-9/10
Content-Length: 10    


1 Answer 1


You should be serving a 206 in this case.

RFC 7233 makes it clear that if any part of the requested range is satisfiable then that is what you send back, even if part of the range is not satisfiable.

From section 2.1:

If a valid byte-range-set includes at least one byte-range-spec with a first-byte-pos that is less than the current length of the representation, or at least one suffix-byte-range-spec with a non-zero suffix-length, then the byte-range-set is satisfiable. Otherwise, the byte-range-set is unsatisfiable.

So if your file is 1000 bytes, and the client requests bytes=501-2000, you will return a 206 and serve bytes 501-1000. (And remember that ranges start from zero, so watch out for off-by-one errors.)

In the case where no part of the range is satisfiable, you send a 416 error, but you do not send any file content. The whole point of the error is that there is nothing to send!

  • no no, thats not what I asked. I meant what if client asked 2000-4000 while file is only 1000 bytes. So server will return 416, but question is, should server write content too ?
    – xmen
    Jul 4, 2014 at 4:28
  • No, you don't send any content in that case. Jul 4, 2014 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.