-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: Content-Length: 0 is not set for PATCH requests with empty body #40978
Comments
Thank you for filing this issue @tharinduwijewardane and welcome to the Go project! I’d like to understand the motivation here. Was there a failure on some intermediate or front end server, say Nginx or is your service breaking due to lack of that 0? I ask because in 9+ years no one had reported this being a problem. Did you discover this perhaps just by a code audit, or an actual failure? Please let us know. The impetus for adding that 0 for POST and PUT is that RFC 2616 says we can include 0 only if the method doesn’t prohibit it, and Nginx apparently needs that too. However, nothing has been reported/requested for DELETE nor PATCH in the past 9 years (almost decade). |
@odeke-em I came across this when invoking the Azure data lake storage gen2 API (https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/update) for flushing the content of a file which was uploaded in a previous request. However, at-least we should be able to manually set the content-length header right? |
Thank you for providing the background, @tharinduwijewardane! I have cited your case in the fixing CL https://go-review.googlesource.com/c/go/+/250039. To get around this, firstly am away from my computer for a couple of hours but I’ve written for you a repro with a stand-alone server using my iPad here https://play.golang.org/p/43_KR2riBiT, please let me know what it prints out on your computer. |
Change https://golang.org/cl/250039 mentions this issue: |
@odeke-em "In server" the content-length header is not received.
|
Thank you for running them! Given that you are the sole reporter in the past 9 years, I don’t think that this could qualify for a backport, but would it be alright for you to use go tip for the next 3+ months until Go1.16 is released? If not, let me know and I can craft up for you a way of hacking in that Content-Length:0 or perhaps request backports to the last 2 Go releases |
Are you sure that rfc2616 defines patch? From my research it was proposed in 2010 in https://tools.ietf.org/html/rfc5789 |
It just says that as long as the method doesn’t forbid sending the
Content-Length, it can be sent which is my interpretation to say that it
doesn’t forbid it.
…On Mon, Aug 24, 2020 at 1:28 AM Dave Cheney ***@***.***> wrote:
Are you sure that rfc2616 defines patch? From my research it was proposed
in 2010 in https://tools.ietf.org/html/rfc5789
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#40978 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABFL3V4B3A7EMLKVNIAVOOTSCIQC5ANCNFSM4QIEEM2Q>
.
|
@odeke-em Thank you. But this is no longer a blocker for me as there is a workaround/hack. |
That’s probably for connection reuse to work. What’s the use case for sending a PATCH with an empty body, surely the server will reject it? |
Thanks Dave for the citations. In regards to the use case, the original
reporter stated that they need to send an empty PATCH request in order to
flush the contents of a file that was previously uploaded, in reply to my
similar question as per
#40978 (comment)
…On Mon, Aug 24, 2020 at 1:36 AM Dave Cheney ***@***.***> wrote:
It just says that as long as the method doesn’t forbid sending the
Content-Length, it can be sent which is my interpretation to say that it
doesn’t forbid it.
… <#m_-5160185177206370588_>
That’s probably for connection reuse to work.
What’s the use case for sending a PATCH with an empty body, surely the
server will reject it?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#40978 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABFL3V443H3YAWDWSSQSOS3SCIRCHANCNFSM4QIEEM2Q>
.
|
Ok, thanks for confirming |
What version of Go are you using (
go version
)?1.15
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?darwin amd64
go env
OutputWhat did you do?
What did you expect to see?
Content-Length
header getting set to 0 when the request is observed from the server side.What did you see instead?
Content-Length
header is not getting set for PATCH requests with empty/nil payload. It is getting set without any issue for other http methods (POST, PUT).It is also getting set for PATCH requests if the payload is non empty.
Also setting
req.Header.Set("Content-Length", "0")
seems to have no effect on the actual content length getting set in the request.The text was updated successfully, but these errors were encountered: