Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fit/hotfix compat hypercorn with http1.1 (#390)

Nahuel Nucera35818a02beec
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 804eb745..2ce69aaa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,13 @@ Versioning follows [Semantic Versioning](https://semver.org/).
---
+## [1.3.4] — 2026-04-20
+
+### Fixed
+- **`Expect: 100-continue` regression on boto3 < 1.40 (S3 `upload_file`)** — after the uvicorn → hypercorn migration in 1.3.0 (#369), boto3 `< 1.40` S3 uploads that used the `Expect: 100-continue` handshake aborted with `urllib3 BadStatusLine('date: ...')`. Root cause: h11 serialises `InformationalResponse` with an empty reason phrase by default, producing `HTTP/1.1 100 \r\n` on the wire, which older urllib3 parses strictly. ministack now installs a surgical compatibility shim at app import (`ministack.core.hypercorn_compat`) that injects the canonical reason phrase (`Continue`, `Switching Protocols`, etc.) when h11 emits an empty one, restoring the pre-1.3.0 behaviour for every SDK version. Reported by @AlbertodelaCruz. Fixes #389
+
+---
+
## [1.3.3] — 2026-04-19
### Added
diff --git a/ministack/app.py b/ministack/app.py
index bce5d0ce..a2a15f70 100644
--- a/ministack/app.py
+++ b/ministack/app.py
@@ -43,10 +43,15 @@ _S3_VHOST_RE = re.compile(
)
_S3_VHOST_EXCLUDE_RE = re.compile(r"\.(execute-api|alb|emr|efs|elasticache|s3-control)\.")
+from ministack.core.hypercorn_compat import install as _install_hypercorn_compat
from ministack.core.persistence import PERSIST_STATE, load_state, save_all
from ministack.core.responses import set_request_account_id
from ministack.core.router import detect_service, extract_access_key_id, extract_account_id, extract_region
+# Must run before hypercorn emits its first Expect: 100-continue reply.
+# See ministack/core/hypercorn_compat.py for the rationale (issue #389).
+_install_hypercorn_compat()
+
# ---------------------------------------------------------------------------
# Lazy service loader — modules are imported on first request, not at startup.
# This saves ~20 MB of idle RAM and speeds up boot.
diff --git a/ministack/core/hypercorn_compat.py b/ministack/core/hypercorn_compat.py
new file mode 100644
index 00000000..e31e13f8
--- /dev/null
+++ b/ministack/core/hypercorn_compat.py
@@ -0,0 +1,43 @@
+"""Compatibility shims for the hypercorn/h11 stack.
+
+h11 serialises ``InformationalResponse`` with an empty reason phrase by
+default, producing ``HTTP/1.1 100 \\r\\n`` on the wire. boto3 < 1.40's
+bundled urllib3 parses this strictly and aborts with ``BadStatusLine``
+when the client is waiting on ``Expect: 100-continue`` (e.g. S3
+``upload_file``). Injecting the standard reason phrase makes the wire
+output ``HTTP/1.1 100 Continue\\r\\n``, which every SDK version accepts.
+
+Issue: https://github.com/ministackorg/ministack/issues/389
+Remove this module if h11 ever ships a default reason upstream.
+"""
+
+import h11
+
+# RFC 9110 § 15.2 informational response reason phrases.
+_DEFAULT_REASONS = {
+ 100: b"Continue",
+ 101: b"Switching Protocols",
+ 102: b"Processing",
+ 103: b"Early Hints",
+}
+
+_original_post_init = h11.InformationalResponse.__post_init__
+
+
+def _patched_post_init(self) -> None:
+ _original_post_init(self)
+ if not self.reason:
+ default = _DEFAULT_REASONS.get(self.status_code)
+ if default is not None:
+ # Frozen dataclass — bypass normal attribute protection.
+ object.__setattr__(self, "reason", default)
+
+
+_patched_post_init._ministack_patched = True # type: ignore[attr-defined]
+
+
+def install() -> None:
+ """Install the reason-phrase patch. Idempotent."""
+ if getattr(h11.InformationalResponse.__post_init__, "_ministack_patched", False):
+ return
+ h11.InformationalResponse.__post_init__ = _patched_post_init
diff --git a/pyproject.toml b/pyproject.toml
index a960317d..bf1bc328 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "ministack"
-version = "1.3.3"
+version = "1.3.4"
description = "Free, open-source local AWS emulator — drop-in LocalStack replacement"
readme = "README.md"
license = { file = "LICENSE" }