Skip to content

Commit

Permalink
fix(webdav): don't retry for put if body isn't seeker (close #4149 close
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed May 11, 2023
1 parent e15755f commit f97f1d5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/gowebdav/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func (c *Client) req(method, path string, body io.Reader, intercept func(*http.Request)) (req *http.Response, err error) {
var r *http.Request
var retryBuf io.Reader

canRetry := true
if body != nil {
// If the authorization fails, we will need to restart reading
// from the passed body stream.
Expand All @@ -25,6 +25,8 @@ func (c *Client) req(method, path string, body io.Reader, intercept func(*http.R
return
}
retryBuf = body
} else if method == http.MethodPut {
canRetry = false
} else {
buff := &bytes.Buffer{}
retryBuf = buff
Expand Down Expand Up @@ -83,7 +85,9 @@ func (c *Client) req(method, path string, body io.Reader, intercept func(*http.R

// retryBuf will be nil if body was nil initially so no check
// for body == nil is required here.
return c.req(method, path, retryBuf, intercept)
if canRetry {
return c.req(method, path, retryBuf, intercept)
}
} else if rs.StatusCode == 401 {
return rs, newPathError("Authorize", c.root, rs.StatusCode)
}
Expand Down Expand Up @@ -193,7 +197,7 @@ func (c *Client) copymove(method string, oldpath string, newpath string, overwri
}

func (c *Client) put(path string, stream io.Reader, callback func(r *http.Request)) (status int, err error) {
rs, err := c.req("PUT", path, stream, callback)
rs, err := c.req(http.MethodPut, path, stream, callback)
if err != nil {
return
}
Expand Down

0 comments on commit f97f1d5

Please sign in to comment.