Check for redirects
This commit was moved from ipfs/go-ipfs-http-client@19c65db4f0fd1549fc6f224efd868d4f00da997d
Łukasz Magiera committed
Feb 6, 2019 at 22:36 UTC
c543354b1772323cb2cfbf41c06522297bf27667
2 files changed
+14
-6
client/httpapi/api.go
+13
-5
@@ -2,6 +2,7 @@ package httpapi
2
3
import (
4
"errors"
5
+ "fmt"
6
"io/ioutil"
7
gohttp "net/http"
8
"os"
@@ -27,7 +28,7 @@ var ErrNotImplemented = errors.New("not implemented")
28
29
type HttpApi struct {
30
url string
30
- httpcli *gohttp.Client
31
+ httpcli gohttp.Client
32
33
applyGlobal func(*RequestBuilder)
34
}
@@ -50,8 +51,8 @@ func NewPathApi(p string) iface.CoreAPI {
51
return NewApi(a)
52
}
53
53
-func ApiAddr(p string) ma.Multiaddr {
54
- baseDir, err := homedir.Expand(p)
54
+func ApiAddr(ipfspath string) ma.Multiaddr {
55
+ baseDir, err := homedir.Expand(ipfspath)
56
if err != nil {
57
return nil
58
}
@@ -99,11 +100,18 @@ func NewApiWithClient(a ma.Multiaddr, c *gohttp.Client) *HttpApi {
100
}
101
}
102
102
- return &HttpApi{
103
+ api := &HttpApi{
104
url: url,
104
- httpcli: c,
105
+ httpcli: *c,
106
applyGlobal: func(*RequestBuilder) {},
107
}
108
+
109
+ // We don't support redirects.
110
+ api.httpcli.CheckRedirect = func(_ *gohttp.Request, _ []*gohttp.Request) error {
111
+ return fmt.Errorf("unexpected redirect")
112
+ }
113
+
114
+ return api
115
}
116
117
func (api *HttpApi) WithOptions(opts ...caopts.ApiOption) (iface.CoreAPI, error) {
client/httpapi/requestbuilder.go
+1
-1
@@ -92,7 +92,7 @@ func (r *RequestBuilder) Send(ctx context.Context) (*Response, error) {
92
req.Opts = r.opts
93
req.Headers = r.headers
94
req.Body = r.body
95
- return req.Send(r.shell.httpcli)
95
+ return req.Send(&r.shell.httpcli)
96
}
97
98
// Exec sends the request a request and decodes the response.