Description
Brief summary
The Hosts
option doesn't work well with non-lowercase hosts, and it causes the k6/http
module to fail with connect: connection refused
even before actually trying to perform any HTTP request.
The problem seems to be originated in the Hosts
type, and more specifically in the Hosts.Match
, because the internal trie succesfully reports the match, but then the Match
function uses the lowercased host to lookup in the map, so if the user didn't specify the host in strict lowercase, it would return an empty host (wouldn't find it).
I've been able to successfully reproduce this issue since v0.42.0
and up to v0.49.0
(including master
).
Related with #3620
k6 version
v0.49.0
OS
Any
Docker version and image (if applicable)
No response
Steps to reproduce the problem
Run any k6 test script with a non-lowercase host (see the example below):
import http from "k6/http";
import {check} from "k6";
export var options = {hosts: {'your-UPPER-case-host.io': 'your-ip'}};
export default function () {
var param = {headers: {'Accept': 'text/html'}};
check(http.get("https://your-UPPER-case-host.io", param), {
"status is 200": (r) => r.status == 200,
"protocol is HTTP/1.1": (r) => r.proto == "HTTP/1.1",
});
}
Expected behaviour
The script execution shouldn't fail despite of the case used to describe the host, as hosts are considered case insensitive as per DNS.
Actual behaviour
Since v0.42.0
(and most specifically, probably since 120436b610070f85f04c524fb20c35202627fcea
) it fails with:
time="2024-03-18T12:21:55Z" level=warning msg="Request Failed" error="Get \"https://your-UPPER-case-host.io\": dial tcp :443: connect: connection refused"
before actually trying to perform any HTTP request.