Skip to content

Commit

Permalink
Always set response.URL to the latest redirect even on errors fix #987
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Apr 8, 2019
1 parent 3506ee1 commit 1e640d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
19 changes: 15 additions & 4 deletions js/modules/k6/http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1425,11 +1425,22 @@ func TestErrorCodes(t *testing.T) {
script: `let res = http.request("GET", "dafsgdhfjg/");`,
},
{
name: "Too many redirects",
status: 302,
name: "Too many redirects",
status: 302,
moreSamples: 2,
script: `
let res = http.get("HTTPBIN_URL/redirect/1", {redirects: 0});
if (res.url != "HTTPBIN_URL/redirect/1") { throw new Error("incorrect URL: " + res.url) }`,
let res = http.get("HTTPBIN_URL/relative-redirect/3", {redirects: 2});
if (res.url != "HTTPBIN_URL/relative-redirect/1") { throw new Error("incorrect URL: " + res.url) }`,
},
{
name: "Connection refused redirect",
status: 0,
moreSamples: 1,
expectedErrorMsg: `dial tcp 127.0.0.1:1: connect: connection refused`,
expectedErrorCode: 1210,
script: `
let res = http.get("HTTPBIN_URL/redirect-to?url=http%3A%2F%2F127.0.0.1%3A1%2Fpesho");
if (res.url != "http://127.0.0.1:1/pesho") { throw new Error("incorrect URL: " + res.url) }`,
},
}

Expand Down
1 change: 1 addition & 0 deletions lib/netext/httpext/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func MakeRequest(ctx context.Context, preq *ParsedHTTPRequest) (*Response, error
Transport: transport,
Timeout: preq.Timeout,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
resp.URL = req.URL.String()
debugResponse(state, req.Response, "RedirectResponse")

// Update active jar with cookies found in "Set-Cookie" header(s) of redirect response
Expand Down

0 comments on commit 1e640d5

Please sign in to comment.