Does k6 not send proxy-header?

Hello k6 community,

I am reaching out with a question because I’ve encountered an issue while trying to run tests with k6’s HTTP library. After setting the HTTPS_PROXY environment variable and executing, I receive an error that says Proxy Authentication Required. Does k6 not pass the headers to the proxy? I believe it should pass them along for the authentication to work properly.

Example

HTTPS_PROXY=http://proxy-server:8080 k6 run test.js --duration=10s -v
import http from "k6/http";
import { sleep, group } from "k6";

export function setup() {
  const token =
    "eyJraWQiOiIwIiwidH....";
  return { token };
}

export default function (data) {
  const { token } = data;
  group("test1", function () {
    console.log(token);

    const response = http.get(
      `https://test-server.com`,
      {
        headers: {
          "Proxy-Authorization": `Bearer ${token}`,
          accept: "*/*"
        },
      }
    );

    console.log(response);
    sleep(10);
  });
}
INFO[0000] Request:
GET / HTTP/1.1
Host: test-server.com
User-Agent: k6/0.43.1 (https://k6.io/)
Accept: */*
Proxy-Authorization: Bearer eyJraWQiOiIwIiwid

  group="test" iter=0 request_id=d160f6bf-1aef-479b-59c8-295d4633ecd2 scenario=default source=http-debug vu=1
WARN[0000] Request Failed                                error="Get \"https://test-server.com\": Proxy Authentication Required"

I found an answer for this question myself.
k6 doesn’t pass the headers of request to the proxy.

Headers({'host': 'reports.k6.io:443', 'user-agent': 'Go-http-client/1.1'})
INFO:     127.0.0.1:55759 - "CONNECT reports.k6.io%3A443 HTTP/1.1" 200 OK
1 Like