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,9 +1,9 @@
package webdav
import (
"encoding/xml"
"fmt"
"net/http"
"strings"
"github.com/emersion/go-webdav/internal"
)
@@ -21,21 +21,15 @@ func NewClient(c *http.Client, endpoint string) (*Client, error) {
}
func (c *Client) FindCurrentUserPrincipal() (string, error) {
r := strings.NewReader(`<?xml version="1.0" encoding="utf-8"?>
<D:propfind xmlns:D="DAV:">
<D:prop>
<D:current-user-principal/>
</D:prop>
</D:propfind>
`)
name := xml.Name{"DAV:", "current-user-principal"}
propfind := internal.NewPropPropfind(name)
req, err := c.c.NewRequest("PROPFIND", "", r)
req, err := c.c.NewXMLRequest("PROPFIND", "", propfind)
if err != nil {
return "", err
}
req.Header.Add("Depth", "0")
req.Header.Add("Content-Type", "text/xml; charset=\"utf-8\"")
resps, err := c.c.DoMultiStatus(req)
if err != nil {