-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/http: handling range requests for empty files #47021
Comments
What specific behavior do you want here? From RFC 7433, Section 4.4:
A request for "bytes=0-0" is a request for the first byte of a resource. If the resource is 0-length, the range RFC 7433, Section 4.4 does also state:
That could be read as stating that a request for [0,0] overlaps a 0-length representation, because the first-byte-pos (0) is not greater than the length (0). However, this interpretation would require responding with a 0-length 206 Partial Content response, which is not possible since the |
@neild thanks for the response I agree with what you said. Using range requests and handling 0 byte files seems like a pretty common case to handle, so my main question was if we could add documentation to the go library for how to handle that case or have a special case for this. When I was looking into it I did find this project issue that talked about using a If you don' t feel it is appropriate for the go library to handle the 0 byte file case then I think it would be good to add something to the documentation so that the next time someone is searching for |
This isn't really a Go issue. There's no way to issue an RFC 7433-conformant request for a range of a 0-length file. A range request is a request for a non-zero-length range of bytes. A 0-length file contains no bytes. I believe that a 416 Range Not Satisfiable response is correct in this situation. There are other correct responses (we could ignore the Range header entirely for 0-length files, for example, and return a 200 response), but I don't see a reason those other possibilities are better. I don't think there's anything surprising about responding to a request for data past the end of a file with, "Sorry, the file isn't that big". A request containing
|
What version of Go are you using (
go version
)?go version go1.16.3 darwin/amd64
Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
In our API package we add a range request to the
HEADER
like soWhen we extended our testing to include zero-byte (ie empty) files we found that the response from the
httpClient.Do
method is416 Requested Range Not Satisfiable
. This was with afrom
andto
values of 0.Now I know that technically that is correct since that range request is asking for the first byte and that doesn't exist in an empty file. However, I could not find in the documentation a way to submit range requests for empty files.
Would it be possible for the standard library to be updated to provided direction on how to submit a range request for an empty file? Or do you expect the caller to make that determination and just not submit a range if it is an empty file.
What did you expect to see?
There should be a standard way to handle a range request for a zero-byte (empty) file.
What did you see instead?
416 Requested Range Not Satisfiable
The text was updated successfully, but these errors were encountered: