mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
internal/server: handle PROPFIND without body
See RFC 4918 section 9.1.
This commit is contained in:
parent
75d3041b41
commit
b043bbd965
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -27,9 +28,13 @@ func ServeError(w http.ResponseWriter, err error) {
|
|||||||
http.Error(w, err.Error(), code)
|
http.Error(w, err.Error(), code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isContentXML(h http.Header) bool {
|
||||||
|
t, _, _ := mime.ParseMediaType(h.Get("Content-Type"))
|
||||||
|
return t == "application/xml" || t == "text/xml"
|
||||||
|
}
|
||||||
|
|
||||||
func DecodeXMLRequest(r *http.Request, v interface{}) error {
|
func DecodeXMLRequest(r *http.Request, v interface{}) error {
|
||||||
t, _, _ := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
if !isContentXML(r.Header) {
|
||||||
if t != "application/xml" && t != "text/xml" {
|
|
||||||
return HTTPErrorf(http.StatusBadRequest, "webdav: expected application/xml request")
|
return HTTPErrorf(http.StatusBadRequest, "webdav: expected application/xml request")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,8 +136,16 @@ 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 err := DecodeXMLRequest(r, &propfind); err != nil {
|
if isContentXML(r.Header) {
|
||||||
return err
|
if err := DecodeXMLRequest(r, &propfind); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var b [1]byte
|
||||||
|
if _, err := r.Body.Read(b[:]); err != io.EOF {
|
||||||
|
return HTTPErrorf(http.StatusBadRequest, "webdav: unsupported request body")
|
||||||
|
}
|
||||||
|
propfind.AllProp = &struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
depth := DepthInfinity
|
depth := DepthInfinity
|
||||||
|
Loading…
Reference in New Issue
Block a user