internal/server: handle "allprop" with empty request and XML content type
The previous code failed to properly handle PROPFIND with an empty request body (RFC 4918 section 9.1) for XML content type requests. Refactor the logic to always consider PROPFIND requests with empty request bodies as "allprop" requests, regardless of content type. There is no need to worry about the request's content type if the request body is empty anyway, so only parse if we know it is not.
This commit is contained in:
parent
e4babc2798
commit
80149e46a4
@ -131,17 +131,17 @@ func (h *Handler) handleOptions(w http.ResponseWriter, r *http.Request) error {
|
|||||||
|
|
||||||
func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) error {
|
func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) error {
|
||||||
var propfind PropFind
|
var propfind PropFind
|
||||||
if isContentXML(r.Header) {
|
if IsRequestBodyEmpty(r) {
|
||||||
|
// NOTE: properly handle PROPFIND requests without a body,
|
||||||
|
// regardless of the "Content-Type" header of the request.
|
||||||
|
propfind.AllProp = &struct{}{}
|
||||||
|
} else if isContentXML(r.Header) {
|
||||||
if err := DecodeXMLRequest(r, &propfind); err != nil {
|
if err := DecodeXMLRequest(r, &propfind); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var b [1]byte
|
|
||||||
if _, err := r.Body.Read(b[:]); err != io.EOF {
|
|
||||||
return HTTPErrorf(http.StatusBadRequest, "webdav: unsupported request body")
|
return HTTPErrorf(http.StatusBadRequest, "webdav: unsupported request body")
|
||||||
}
|
}
|
||||||
propfind.AllProp = &struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
depth := DepthInfinity
|
depth := DepthInfinity
|
||||||
if s := r.Header.Get("Depth"); s != "" {
|
if s := r.Header.Get("Depth"); s != "" {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user