Merge branch 'b12-master'
This commit is contained in:
commit
f821ab73e9
15
.gitignore
vendored
15
.gitignore
vendored
@ -1,6 +1,19 @@
|
|||||||
|
# Folders to ignore
|
||||||
/src
|
/src
|
||||||
/bin
|
/bin
|
||||||
/pkg
|
/pkg
|
||||||
/gowebdav
|
/gowebdav
|
||||||
.idea/
|
/.idea
|
||||||
|
|
||||||
|
# Binaries for programs and plugins
|
||||||
*.exe
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Test binary, build with `go test -c`
|
||||||
|
*.test
|
||||||
|
|
||||||
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
|
*.out
|
||||||
|
16
requests.go
16
requests.go
@ -12,10 +12,16 @@ import (
|
|||||||
|
|
||||||
func (c *Client) req(method, path string, body io.Reader, intercept func(*http.Request)) (req *http.Response, err error) {
|
func (c *Client) req(method, path string, body io.Reader, intercept func(*http.Request)) (req *http.Response, err error) {
|
||||||
// Tee the body, because if authorization fails we will need to read from it again.
|
// Tee the body, because if authorization fails we will need to read from it again.
|
||||||
|
var r *http.Request
|
||||||
var ba bytes.Buffer
|
var ba bytes.Buffer
|
||||||
bb := io.TeeReader(body, &ba)
|
bb := io.TeeReader(body, &ba)
|
||||||
|
|
||||||
r, err := http.NewRequest(method, PathEscape(Join(c.root, path)), &ba)
|
if body == nil {
|
||||||
|
r, err = http.NewRequest(method, PathEscape(Join(c.root, path)), nil)
|
||||||
|
} else {
|
||||||
|
r, err = http.NewRequest(method, PathEscape(Join(c.root, path)), bb)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -42,7 +48,13 @@ func (c *Client) req(method, path string, body io.Reader, intercept func(*http.R
|
|||||||
} else {
|
} else {
|
||||||
return rs, newPathError("Authorize", c.root, rs.StatusCode)
|
return rs, newPathError("Authorize", c.root, rs.StatusCode)
|
||||||
}
|
}
|
||||||
return c.req(method, path, bb, intercept)
|
|
||||||
|
if body == nil {
|
||||||
|
return c.req(method, path, nil, intercept)
|
||||||
|
} else {
|
||||||
|
return c.req(method, path, &ba, intercept)
|
||||||
|
}
|
||||||
|
|
||||||
} else if rs.StatusCode == 401 {
|
} else if rs.StatusCode == 401 {
|
||||||
return rs, newPathError("Authorize", c.root, rs.StatusCode)
|
return rs, newPathError("Authorize", c.root, rs.StatusCode)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user