Skip to content

Commit cb9490d

Browse files
committed
do not allow auto redirect to http client
1 parent f2d32b0 commit cb9490d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

aws-es-proxy.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type proxy struct {
5252
fileRequest *os.File
5353
fileResponse *os.File
5454
credentials *credentials.Credentials
55+
client *http.Client
5556
}
5657

5758
func newProxy(args ...interface{}) *proxy {
@@ -64,6 +65,14 @@ func newProxy(args ...interface{}) *proxy {
6465
}
6566
}
6667

68+
var client = &http.Client{
69+
CheckRedirect: noRedirect,
70+
}
71+
72+
func noRedirect(req *http.Request, via []*http.Request) error {
73+
return http.ErrUseLastResponse
74+
}
75+
6776
func (p *proxy) parseEndpoint() error {
6877
var link *url.URL
6978
var err error
@@ -149,7 +158,7 @@ func (p *proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
149158
signer.Sign(req, payload, p.service, p.region, time.Now())
150159
}
151160

152-
resp, err := http.DefaultClient.Do(req)
161+
resp, err := client.Do(req)
153162
if err != nil {
154163
log.Fatalln(err.Error())
155164
http.Error(w, err.Error(), http.StatusBadRequest)

0 commit comments

Comments
 (0)