diff --git a/kraken-std/.changelog/_unreleased.toml b/kraken-std/.changelog/_unreleased.toml index b6e3925e..ae336f83 100644 --- a/kraken-std/.changelog/_unreleased.toml +++ b/kraken-std/.changelog/_unreleased.toml @@ -11,3 +11,9 @@ type = "improvement" description = "Support pytest coverage." author = "benjamin.poumarede@helsing.ai" pr = "https://github.com/kraken-build/kraken-build/pull/48" + +[[entries]] +id = "b240870c-57c7-408a-a8f7-ee9db06fb475" +type = "improvement" +description = "Add `--no-http2` to the mitmproxy when invoked via the Cargo auth proxy task. This is to work around an issue with Cargo HTTP/2 multi-plexing (see https://github.com/rust-lang/cargo/issues/12202)." +author = "@NiklasRosenstein" diff --git a/kraken-std/src/kraken/std/cargo/tasks/cargo_auth_proxy_task.py b/kraken-std/src/kraken/std/cargo/tasks/cargo_auth_proxy_task.py index 0d19d1c8..4c9b221b 100644 --- a/kraken-std/src/kraken/std/cargo/tasks/cargo_auth_proxy_task.py +++ b/kraken-std/src/kraken/std/cargo/tasks/cargo_auth_proxy_task.py @@ -3,7 +3,7 @@ import contextlib import logging import time -from collections.abc import Iterator +from collections.abc import Iterator, Sequence from pathlib import Path from urllib.parse import urlparse @@ -41,6 +41,11 @@ class CargoAuthProxyTask(BackgroundTask): #: The number of seconds to wait after the proxy started. startup_wait_time: Property[float] = Property.default(1.0) + #: Additional args for the mitmproxy. + #: We pass `--no-http2` by default as that breaks Cargo HTTP/2 multiplexing. See + #: https://github.com/rust-lang/cargo/issues/12202 + mitmproxy_additional_args: Property[Sequence[str]] = Property.default_factory(lambda: ["--no-http2"]) + @contextlib.contextmanager def _inject_config(self) -> Iterator[None]: """Injects the proxy URL and cert file into the Cargo and Git configuration.""" @@ -94,7 +99,7 @@ def start_background_task(self, exit_stack: contextlib.ExitStack) -> TaskStatus: host = not_none(urlparse(registry.index).hostname) auth[host] = registry.read_credentials - proxy_url, cert_file = start_mitmweb_proxy(auth=auth) + proxy_url, cert_file = start_mitmweb_proxy(auth=auth, additional_args=self.mitmproxy_additional_args.get()) self.proxy_url.set(proxy_url) self.proxy_cert_file.set(cert_file) exit_stack.callback(lambda: self.proxy_url.clear()) diff --git a/kraken-std/src/kraken/std/mitm/__init__.py b/kraken-std/src/kraken/std/mitm/__init__.py index d89c8d5f..8d5752ad 100644 --- a/kraken-std/src/kraken/std/mitm/__init__.py +++ b/kraken-std/src/kraken/std/mitm/__init__.py @@ -9,7 +9,7 @@ import json import logging import time -from collections.abc import Mapping +from collections.abc import Mapping, Sequence from pathlib import Path from kraken.std.util.daemon_controller import DaemonController @@ -24,7 +24,9 @@ inject_auth_addon_file = Path(__file__).parent / "mitm_addon.py" -def start_mitmweb_proxy(auth: Mapping[str, tuple[str, str]], startup_wait_time: float = 3.0) -> tuple[str, Path]: +def start_mitmweb_proxy( + auth: Mapping[str, tuple[str, str]], startup_wait_time: float = 3.0, additional_args: Sequence[str] = () +) -> tuple[str, Path]: controller = DaemonController("kraken.mitmweb", daemon_state_file) started = controller.run( command=[ @@ -47,6 +49,7 @@ def start_mitmweb_proxy(auth: Mapping[str, tuple[str, str]], startup_wait_time: # context. "--set", "stream_large_bodies=3m", + *additional_args, ], cwd=Path("~").expanduser(), stdout=daemon_log_file,