Tim Visser
Tim Visser

Reputation: 919

What is the professional way of serving HTTP 206 responses

If a server is set-up to handle Range requests, by accepting bytes for instance, then there are roughly two ways of sending a valid request to that server.

The first is to set the Range header to something like Range: 0-, meaning that we want the first byte of whatever the server is serving and are lazy about the rest of the content. Just give us as much as the server can.

The second is to set the Range header to something like Range: 0-2000/*, meaning that we explicitly want bytes 0 through 2000 and we don't care how large the file is that the server is serving.

These requests - if deemed valid by the server (which we now state, is indeed valid) - are then answered by HTTP 206 responses.

My question is: what is the most professional approach to serving a file through Partial responses, as discussed above. Would it be serving all bytes the client who sent the request does not have at once, i.e. if a request with Range: 0- comes in serving bytes 0 through the last byte? Or would it be to split up the file and when a request with Range: 0- comes in only serve a number of bytes, i.e. bytes 0 through 500? Or something different alltogether?

I have this question because a current code base of mine seems to be blocking, thus no more than five or so requests can be handled at a given time.

Upvotes: 1

Views: 309

Answers (1)

Evert
Evert

Reputation: 99687

From RFC7233, section 2.1:

A client can limit the number of bytes requested without knowing the size of the selected representation. If the last-byte-pos value is absent, or if the value is greater than or equal to the current length of the representation data, the byte range is interpreted as the remainder of the representation (i.e., the server replaces the value of last-byte-pos with a value that is one less than the current length of the selected representation).

So this means that a range like:

Range: 0-

Should be interpreted as 'serve the entire file'.

Upvotes: 1

Related Questions