Skip to content

Commit

Permalink
Dont skip host in http.Response.headers (grafana#1744)
Browse files Browse the repository at this point in the history
  • Loading branch information
noelzubin authored Dec 2, 2020
1 parent ddee5dd commit cfedc92
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
6 changes: 2 additions & 4 deletions js/modules/k6/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,10 @@ func (h *HTTP) parseRequest(
}
for _, key := range headers.Keys() {
str := headers.Get(key).String()
switch strings.ToLower(key) {
case "host":
if strings.ToLower(key) == "host" {
result.Req.Host = str
default:
result.Req.Header.Set(key, str)
}
result.Req.Header.Set(key, str)
}
case "jar":
jarV := params.Get(k)
Expand Down
25 changes: 25 additions & 0 deletions js/modules/k6/http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,31 @@ func TestRequestAndBatch(t *testing.T) {
assert.NoError(t, err)
assertRequestMetricsEmitted(t, stats.GetBufferedSamples(samples), "GET", sr("HTTPBIN_URL/headers"), "", 200, "")
})

t.Run("response_request", func(t *testing.T) {
_, err := common.RunString(rt, sr(`
var res = http.request("GET", "HTTPBIN_URL/headers", null, {
headers: { "host": "HTTPBIN_DOMAIN" },
});
if (res.status != 200) { throw new Error("wrong status: " + res.status); }
if (res.request.headers["Host"] != "HTTPBIN_DOMAIN") { throw new Error("wrong Host: " + res.request.headers["Host"]); }
`))
assert.NoError(t, err)
assertRequestMetricsEmitted(t, stats.GetBufferedSamples(samples), "GET", sr("HTTPBIN_URL/headers"), "", 200, "")
})

t.Run("differentHost", func(t *testing.T) {
_, err := common.RunString(rt, sr(`
var custHost = 'k6.io';
var res = http.request("GET", "HTTPBIN_URL/headers", null, {
headers: { "host": custHost },
});
if (res.status != 200) { throw new Error("wrong status: " + res.status); }
if (res.request.headers["Host"] != custHost) { throw new Error("wrong Host: " + res.request.headers["Host"]); }
`))
assert.NoError(t, err)
assertRequestMetricsEmitted(t, stats.GetBufferedSamples(samples), "GET", sr("HTTPBIN_URL/headers"), "", 200, "")
})
})

t.Run("tags", func(t *testing.T) {
Expand Down

0 comments on commit cfedc92

Please sign in to comment.