mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
Add Client.SetBasicAuth
This commit is contained in:
parent
dbdd296d38
commit
cabf33219e
@ -28,6 +28,11 @@ func NewClient(c *http.Client, endpoint string) (*Client, error) {
|
|||||||
return &Client{wc, ic}, nil
|
return &Client{wc, ic}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) SetBasicAuth(username, password string) {
|
||||||
|
c.Client.SetBasicAuth(username, password)
|
||||||
|
c.ic.SetBasicAuth(username, password)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) FindAddressBookHomeSet(principal string) (string, error) {
|
func (c *Client) FindAddressBookHomeSet(principal string) (string, error) {
|
||||||
name := xml.Name{namespace, "addressbook-home-set"}
|
name := xml.Name{namespace, "addressbook-home-set"}
|
||||||
propfind := internal.NewPropNamePropfind(name)
|
propfind := internal.NewPropNamePropfind(name)
|
||||||
|
@ -19,6 +19,10 @@ func NewClient(c *http.Client, endpoint string) (*Client, error) {
|
|||||||
return &Client{ic}, nil
|
return &Client{ic}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) SetBasicAuth(username, password string) {
|
||||||
|
c.c.SetBasicAuth(username, password)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) FindCurrentUserPrincipal() (string, error) {
|
func (c *Client) FindCurrentUserPrincipal() (string, error) {
|
||||||
name := xml.Name{"DAV:", "current-user-principal"}
|
name := xml.Name{"DAV:", "current-user-principal"}
|
||||||
propfind := internal.NewPropNamePropfind(name)
|
propfind := internal.NewPropNamePropfind(name)
|
||||||
|
@ -54,6 +54,8 @@ func (d Depth) String() string {
|
|||||||
type Client struct {
|
type Client struct {
|
||||||
http *http.Client
|
http *http.Client
|
||||||
endpoint *url.URL
|
endpoint *url.URL
|
||||||
|
username, password string
|
||||||
|
insecure bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(c *http.Client, endpoint string) (*Client, error) {
|
func NewClient(c *http.Client, endpoint string) (*Client, error) {
|
||||||
@ -65,7 +67,12 @@ func NewClient(c *http.Client, endpoint string) (*Client, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &Client{c, u}, nil
|
return &Client{http: c, endpoint: u}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) SetBasicAuth(username, password string) {
|
||||||
|
c.username = username
|
||||||
|
c.password = password
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) NewRequest(method string, href string, body io.Reader) (*http.Request, error) {
|
func (c *Client) NewRequest(method string, href string, body io.Reader) (*http.Request, error) {
|
||||||
@ -96,8 +103,9 @@ func (c *Client) NewXMLRequest(method string, href string, v interface{}) (*http
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Do(req *http.Request) (*http.Response, error) {
|
func (c *Client) Do(req *http.Request) (*http.Response, error) {
|
||||||
// TODO: remove this quirk
|
if c.username != "" || c.password != "" {
|
||||||
req.SetBasicAuth("emersion", "")
|
req.SetBasicAuth(c.username, c.password)
|
||||||
|
}
|
||||||
return c.http.Do(req)
|
return c.http.Do(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user