Skip to content

Support setting an "Authorization" and a "Proxy-Authorization" HTTP request headers. - #5038

Open
amejia1 wants to merge 8 commits into
rust-lang:mainfrom
amejia1:main
Open

Support setting an "Authorization" and a "Proxy-Authorization" HTTP request headers.#5038
amejia1 wants to merge 8 commits into
rust-lang:mainfrom
amejia1:main

Conversation

@amejia1

@amejia1 amejia1 commented Aug 30, 2026

Copy link
Copy Markdown

The "Authorization" request header is used to authenticate to rustup distribution mirrors that require authentication. The "Proxy-Authorization" request header is used to authenticate to proxies.

This change introduces the new "rustup-mock-server" and "rustup-mock-proxy" test binaries, which are used to test the proper functioning of the new support for the "Authorization" and "Proxy-Authorization" HTTP request headers. A "test-rustup-init.sh" script has also been added to test the proper functioning of the "rustup-init.sh" script with the newly supported request headers.

As part of this change, "rustup-init.sh" was also modified to support distribution servers and proxies running on the localhost using HTTP. This not only provides the benefit of being able to use the "rustup-mock-server" and "rustup-mock-proxy" to run tests, it also provides additional support for custom servers and proxies which run on the localhost and forward requests to corporate servers that may require more elaborate forms of authentication, such as the usage of cookies or the usage of mTLS.

It doesn't seem like putting a disclaimer that AI agents were used is necessary. In any case, at least for the benefit of those that may have been using AI agents for much longer than I have, these code changes were made with the assistance of AI agents. I used a local LLM running this Qwen3.8-27B model.

This addresses #1343 .

I had a previous PR to offer similar functionality (see #4672 ). I decided to redo the code changes entirely, using a locally built mock server and proxy for the tests instead of relying on containers. I also decided to redo the changes with the aid of an AI agent.

…equest headers.

The "Authorization" request header is used to authenticate to rustup
distribution mirrors that require authentication. The
"Proxy-Authorization" request header is used to authenticate to proxies.

This change introduces the new "rustup-mock-server" and
"rustup-mock-proxy" test binaries, which are used to test the proper
functioning of the new support for the "Authorization" and
"Proxy-Authorization" HTTP request headers. A "test-rustup-init.sh"
script has also been added to test the proper functioning of the
"rustup-init.sh" script with the newly supported request headers.

As part of this change, "rustup-init.sh" was also modified to support
distribution servers and proxies running on the localhost using HTTP.
This not only provides the benefit of being able to use the
"rustup-mock-server" and "rustup-mock-proxy" to run tests, it also
provides additional support for custom servers and proxies which run on
the localhost and forward requests to corporate servers that may
require more elaborate forms of authentication, such as the usage of
cookies or the usage of mTLS.
Adding the `rustup-mock-server` and `rustup-mock-proxy` binaries made
`cargo run` without `--bin` ambiguous, as the package no longer has a
single binary to run by default. Set `default-run` to `rustup-init` to
restore the previous behavior of `cargo run`.
The `check` CI job formats all TOML files with taplo and fails on
any difference; the `base64` dependency added by the previous commit
was not in taplo's expected position.
The CI build images ship a non-rustup Rust (at /rustc-sysroot/bin),
which makes rustup-init prompt "Continue?" before installing and
abort when the piped input is not "yes". Set
RUSTUP_INIT_SKIP_PATH_CHECK in the mock-based tests, as the clitools
test infrastructure already does (src/test/clitools.rs), so the
check is skipped there.
The assertion rendered the path to a string and checked that it ends
with ".local/share/...", which fails on Windows, where path
separators are backslashes. Compare the final path components
instead, and inject the home directory so the test does not depend
on the ambient environment.
On Windows, rustup-init prompts to install Visual C++ when the MSVC
build tools are missing, which breaks the hermetic tests on such
machines. Set RUSTUP_INIT_SKIP_MSVC_CHECK in the mock-based tests, as
with the rustc/cargo-in-PATH check and as the clitools test
infrastructure does (src/test/clitools.rs).
On Windows, the default data file location for rustup-mock-server
and rustup-mock-proxy is now under the LOCALAPPDATA directory,
falling back to C:\Users\%USER%\AppData\Local and then to the
system temporary directory. The platform-specific fallback logic
lives in pure helpers (unix_default_dir and windows_default_dir)
that take their inputs as parameters, so it is unit-tested on
every platform.
On Windows, rustup-init prompts "Press the Enter key to continue"
after a successful install and aborts when stdin is exhausted. The
mock-based tests piped a single "1" to answer the installation
menu, which left nothing for that second prompt. Invoke rustup-init
with -y instead, the same unattended flag the other rustup-init
tests use (e.g. tests/suite/cli_exact.rs), so no prompt reads from
stdin at all.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant