mirror of https://github.com/Xhofe/alist
perf(webdav): support request with cookies (#5391)
parent
8ef8023c20
commit
aaffaee2b5
|
@ -2,6 +2,7 @@ package webdav
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
|
||||
"github.com/alist-org/alist/v3/drivers/webdav/odrvcookie"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
|
@ -26,6 +27,13 @@ func (d *WebDav) setClient() error {
|
|||
} else {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
cookieJar, err := cookiejar.New(nil)
|
||||
if err == nil {
|
||||
c.SetJar(cookieJar)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
d.client = c
|
||||
return nil
|
||||
|
|
|
@ -83,6 +83,11 @@ func (c *Client) SetTransport(transport http.RoundTripper) {
|
|||
c.c.Transport = transport
|
||||
}
|
||||
|
||||
// SetJar exposes the ability to set a cookie jar to the client.
|
||||
func (c *Client) SetJar(jar http.CookieJar) {
|
||||
c.c.Jar = jar
|
||||
}
|
||||
|
||||
// Connect connects to our dav server
|
||||
func (c *Client) Connect() error {
|
||||
rs, err := c.options("/")
|
||||
|
@ -351,6 +356,11 @@ func (c *Client) Link(path string) (string, http.Header, error) {
|
|||
return "", nil, newPathErrorErr("Link", path, err)
|
||||
}
|
||||
|
||||
if c.c.Jar != nil {
|
||||
for _, cookie := range c.c.Jar.Cookies(r.URL) {
|
||||
r.AddCookie(cookie)
|
||||
}
|
||||
}
|
||||
for k, vals := range c.headers {
|
||||
for _, v := range vals {
|
||||
r.Header.Add(k, v)
|
||||
|
|
Loading…
Reference in New Issue