Open y805939188 opened 8 months ago
@y805939188 In the future, please post text instead of images. The images are less accessible and more difficult to play around with (copy and paste somewhere else, for example).
Also, I'm just triaging and not an expert here, but it seems like this might be a bug in github.com/hacdias/webdav? What makes you think this is a bug in the Go standard library? Or is it the error message that's the problem?
Thanks.
CC @neild
@y805939188 In the future, please post text instead of images. The images are less accessible and more difficult to play around with (copy and paste somewhere else, for example).
Also, I'm just triaging and not an expert here, but it seems like this might be a bug in github.com/hacdias/webdav? What makes you think this is a bug in the Go standard library? Or is it the error message that's the problem?
Thanks.
CC @neild
Hello! I will try to use detailed text and images to describe the problem. I think it may be an issue in Go's net/webdav
package. There is a function named ServeHTTP
in net/webdav/webdav.go
that handles the methods PROPFIND
and PROPPATCH
with the functions status, err = h.handlePropfind(w, r)
and status, err = h.handleProppatch(w, r)
:
There is a code path of ServerHTTP
-> handlePropfind
-> walkFn
-> mw.write
, the function mw.write
calls the w.writeHeader
to write the 207
response code and returns w.enc.Encode(r)
in x/net/webdav/xml.go
, the w.enc.Encoder(r)
function returns an error
type:
And the error from w.enc.Encoder(r)
will be returned to the ServerHTTP
function from h.handlePropfind(w, r)
But in the ServeHTTP
function, if an error
type is returned from handlePropfind
, ServeHTTP
will call WriteHeader
to write a 500
code into response header:
But in the mw.write
function, the HTTP status code 207 has been written into the response header. As a result, the WebDAV client will receive a response with the 207 status code, even though an error related to a superfluous response.WriteHeader call
occurred on the server side.
In summary, when the x/net/webdav/webdav.go
file is handling PROPFIND
or PROPPATCH
methods, if an error occurs on the server side, w.WriteHeader
may be triggered twice.
Go version
go version go1.21.6 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
I tried to modify http request method from
HEAD
toPROPFIND
so that I can mock thePROPFIND
request. As follows:I realize that it is not a right approach after testing. But I got a confusing error message
http: superfluous response.WriteHeader call from github.com/hacdias/webdav/v4/lib.responseWriterNoBody.WriteHeader (webdav.go:222)
:And my webdav client received a
207
response:What did you see happen?
I got a confusing error message
http: superfluous response.WriteHeader call from github.com/hacdias/webdav/v4/lib.responseWriterNoBody.WriteHeader (webdav.go:222)
and207
response. I tried to debug the code, I found that I would get anshort write
error in thishandlePropfind
functionBut before triggering this error, the status code of
207
had already been written into the response header:So in the outermost function used to handle
PROPFIND
orPROPPATCH
methods, when astatus
witherr
was returned, theWriteHeader
was called again, resulting in the client receive a207
response and the server side get ansuperfluous response.WriteHeader call
error.What did you expect to see?
I have given up using
head
to simulatepropfind
, but I hope that when processing thePROPFIND
orPROPPATCH
methods, if the server side encounters an error, it can return500
instead of207