Generate PROPFIND request body

Instead of a hardcoded string, generate it with encoding/xml.
This commit is contained in:
Simon Ser
2020-01-14 20:00:54 +01:00
parent 6f9ff62747
commit 87a88d6723
4 changed files with 47 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
package internal
import (
"bytes"
"encoding/xml"
"fmt"
"io"
@@ -36,6 +37,27 @@ func (c *Client) NewRequest(method string, p string, body io.Reader) (*http.Requ
return http.NewRequest(method, u.String(), body)
}
func (c *Client) NewXMLRequest(method string, p string, v interface{}) (*http.Request, error) {
var buf bytes.Buffer
buf.WriteString(xml.Header)
enc := xml.NewEncoder(&buf)
if err := enc.Encode(v); err != nil {
return nil, err
}
if err := enc.Flush(); err != nil {
return nil, err
}
req, err := c.NewRequest(method, p, &buf)
if err != nil {
return nil, err
}
req.Header.Add("Content-Type", "text/xml; charset=\"utf-8\"")
return req, nil
}
func (c *Client) Do(req *http.Request) (*http.Response, error) {
// TODO: remove this quirk
req.SetBasicAuth("simon", "")