Skip to content

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

fix(alb): preserve repeated HTTP target response headers (#1987)

Adrian-Ryan Acala4f644b5b0643
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2e0a46dd..ec23b5bd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
### Fixed
+- **ALB — repeated HTTP target response headers** — forwards every `Set-Cookie` as a separate header, preserving cookie attributes and repeated fields even when their names use different casing; previously only the first value survived.
- **Aurora DSQL — the 8-key index limit comes first** — measured live, DSQL reports `54011` before the mode, key-expression and `INCLUDE` rules; the proxy reported those first, so a plain `CREATE INDEX` on nine columns drew "unsupported mode". `sys.jobs.details` is now NULL for a job that succeeded, where it was an empty string. Contributed by @vivedo.
- **Aurora DSQL — `CALL sys.wait_for_job($1)` with a bound job id** — a job id bound as a parameter over the extended protocol went through to the backing Postgres and failed `3F000` schema "sys" does not exist, after the index had been built. Bound job ids now work for `sys.wait_for_job` and for `sys.jobs ... WHERE job_id = $1`, and `CALL` answers the procedure's `succeeded` column with the `CALL` tag, as measured on the live service (eu-central-1, 2026-10-04); a malformed id is refused `22P02`. `CREATE INDEX ASYNC` and `ALTER TABLE ASYNC` answer the `CREATE INDEX` / `ALTER TABLE` tags, `sys.jobs` declares its `oid` and `timestamptz` columns, a constraint validation job carries `class_id` 2606, and a unique index that fails on duplicates reports the service's `details`. Contributed by @vivedo.
- **Aurora DSQL — `TimeZone` missing at startup** — the proxy's startup greeting reported no `TimeZone`, so a driver that decodes `timestamptz` by it could stall on the first value; it now reports `TimeZone`, `IntervalStyle` and the rest of the parameters the live service does. Contributed by @vivedo.
diff --git a/ministack/services/alb.py b/ministack/services/alb.py
index b613835f..13134612 100644
--- a/ministack/services/alb.py
+++ b/ministack/services/alb.py
@@ -1894,7 +1894,14 @@ async def _proxy_http_target(target, tg, method, path, headers, body, query_para
return (502, {"Content-Type": "application/json"},
json.dumps({"message": f"Target {host}:{port} connect error: {err}"}).encode())
- status, out_headers = resp.status, dict(resp.headers)
+ # Header names are case-insensitive; repeated fields must reach ASGI as
+ # separate values, especially Set-Cookie whose Expires can contain commas.
+ out_headers = {}
+ for name, value in resp.getheaders():
+ out_headers.setdefault(name.lower(), []).append(value)
+ out_headers = {name: values[0] if len(values) == 1 else values
+ for name, values in out_headers.items()}
+ status = resp.status
async def _stream(send, receive):
disconnected = asyncio.create_task(_await_http_disconnect(receive))
diff --git a/tests/test_alb.py b/tests/test_alb.py
index 63a85882..c961c660 100644
--- a/tests/test_alb.py
+++ b/tests/test_alb.py
@@ -995,6 +995,53 @@ def _start_raw_server(script):
return sock, thread
[email protected]("chunked", [False, True], ids=["content-length", "chunked"])
[email protected]("cookie_names", [
+ ["Set-Cookie", "Set-Cookie", "Set-Cookie"],
+ ["Set-Cookie", "set-cookie", "SET-COOKIE"],
+], ids=["same-case", "mixed-case"])
+def test_elbv2_dataplane_preserves_repeated_target_headers(elbv2, chunked, cookie_names):
+ """Target cookies remain separate fields, including mixed-case names."""
+ cookies = [
+ "session=abc; Path=/; HttpOnly",
+ "theme=dark; Expires=Wed, 09 Jun 2027 10:18:14 GMT; Path=/",
+ "session=def; Path=/admin; Secure",
+ ]
+ body = b"target response"
+
+ def _script(conn):
+ framing = (b"Transfer-Encoding: chunked\r\n" if chunked
+ else f"Content-Length: {len(body)}\r\n".encode())
+ cookie_fields = b"".join(f"{name}: {value}\r\n".encode()
+ for name, value in zip(cookie_names, cookies))
+ conn.sendall(
+ b"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n"
+ + cookie_fields
+ + b"X-Target: first\r\nx-target: second\r\n"
+ + framing + b"\r\n"
+ + (b"%x\r\n%s\r\n0\r\n\r\n" % (len(body), body) if chunked else body)
+ )
+
+ sock, thread = _start_raw_server(_script)
+ lb_name = f"dp-alb-headers-{_uuid_mod.uuid4().hex[:8]}"
+ lb_arn, tg_arn, l_arn = _alb_http_target_setup(
+ elbv2, lb_name, "127.0.0.1", sock.getsockname()[1]
+ )
+ try:
+ with _req.urlopen(f"{_endpoint}/_alb/{lb_name}/", timeout=10) as resp:
+ assert resp.status == 200
+ assert resp.headers.get_all("Set-Cookie") == cookies
+ assert resp.headers.get_all("X-Target") == ["first", "second"]
+ assert resp.headers.get("Content-Type") == "text/plain"
+ assert resp.headers.get("Content-Length") == (None if chunked else str(len(body)))
+ assert (resp.headers.get("Transfer-Encoding") or "").lower() == ("chunked" if chunked else "")
+ assert resp.read() == body
+ finally:
+ _alb_http_target_teardown(elbv2, lb_arn, tg_arn, l_arn)
+ sock.close()
+ thread.join(timeout=5)
+
+
@pytest.mark.serial
def test_elbv2_dataplane_connection_close_target_gets_the_idle_timeout(elbv2):
"""A `Connection: close` target must be bounded by the idle timeout too.