Skip to content

Commit

Permalink
perf(webdav): support request with cookies (#5391)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmugu committed Oct 19, 2023
1 parent 8ef8023 commit aaffaee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/webdav/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions pkg/gowebdav/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit aaffaee

Please sign in to comment.