Skip to content

Commit

Permalink
kraken-std/: improvement: Add --no-http2 to the mitmproxy when invo…
Browse files Browse the repository at this point in the history
…ked via the Cargo auth proxy task. This is to work around an issue with Cargo HTTP/2 multi-plexing (see rust-lang/cargo#12202).
  • Loading branch information
NiklasRosenstein committed Jul 13, 2023
1 parent 8bd2f97 commit d6499a6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions kraken-std/.changelog/_unreleased.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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())
Expand Down
7 changes: 5 additions & 2 deletions kraken-std/src/kraken/std/mitm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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=[
Expand All @@ -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,
Expand Down

0 comments on commit d6499a6

Please sign in to comment.