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