mirror of
https://github.com/1f349/go-webdav.git
synced 2025-01-11 01:46:26 +00:00
internal: add IsRequestEmpty
This commit is contained in:
parent
71bd967b43
commit
f1d56f2437
@ -5,7 +5,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
@ -703,13 +702,7 @@ func (b *backend) Mkcol(r *http.Request) error {
|
|||||||
Path: r.URL.Path,
|
Path: r.URL.Path,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a request body was sent
|
if !internal.IsRequestBodyEmpty(r) {
|
||||||
_, err := r.Body.Read(nil)
|
|
||||||
if err != nil && err != io.EOF {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
// Not EOF, body is present
|
|
||||||
var m mkcolReq
|
var m mkcolReq
|
||||||
if err := internal.DecodeXMLRequest(r, &m); err != nil {
|
if err := internal.DecodeXMLRequest(r, &m); err != nil {
|
||||||
return internal.HTTPErrorf(http.StatusBadRequest, "carddav: error parsing mkcol request: %s", err.Error())
|
return internal.HTTPErrorf(http.StatusBadRequest, "carddav: error parsing mkcol request: %s", err.Error())
|
||||||
@ -722,6 +715,7 @@ func (b *backend) Mkcol(r *http.Request) error {
|
|||||||
ab.Description = m.Description.Description
|
ab.Description = m.Description.Description
|
||||||
// TODO ...
|
// TODO ...
|
||||||
}
|
}
|
||||||
|
|
||||||
return b.Backend.CreateAddressBook(r.Context(), ab)
|
return b.Backend.CreateAddressBook(r.Context(), ab)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,11 @@ func DecodeXMLRequest(r *http.Request, v interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsRequestBodyEmpty(r *http.Request) bool {
|
||||||
|
_, err := r.Body.Read(nil)
|
||||||
|
return err == io.EOF
|
||||||
|
}
|
||||||
|
|
||||||
func ServeXML(w http.ResponseWriter) *xml.Encoder {
|
func ServeXML(w http.ResponseWriter) *xml.Encoder {
|
||||||
w.Header().Add("Content-Type", "text/xml; charset=\"utf-8\"")
|
w.Header().Add("Content-Type", "text/xml; charset=\"utf-8\"")
|
||||||
w.Write([]byte(xml.Header))
|
w.Write([]byte(xml.Header))
|
||||||
|
Loading…
Reference in New Issue
Block a user