Skip to content

Commit

Permalink
Enable binary support by default for ALB events
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Oct 7, 2024
1 parent bbafe4b commit b1843f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Changelog

Thanks to Zoe Guillen for the report in `PR #496 <https://github.com/adamchainz/apig-wsgi/pull/496>`__.

* Enable binary support by default for ALB events.

Thanks to Oliver Ford for the report in `Issue #513 <https://github.com/adamchainz/apig-wsgi/issues/513>`__.

* Treat the content-type header "application/problem+json" as non binary by default.

Thanks to Ido Savion in `PR #503 <https://github.com/adamchainz/apig-wsgi/pull/503>`__.
Expand Down
14 changes: 12 additions & 2 deletions src/apig_wsgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,23 @@ def handler(event: dict[str, Any], context: Any) -> dict[str, Any]:
version = event.get("version", "1.0")

if version in ("1.0", "alb"):
# Binary support deafults 'off' on version 1
event_binary_support = binary_support or False
environ = get_environ_v1(
event,
context,
encode_query_params=(version == "1.0"),
)
if version == "1.0":
# Binary support defaults to 'off' on version 1
if binary_support is None:
event_binary_support = False
else:
event_binary_support = binary_support
else:
# Binary support defaults to 'on' on ALBs
if binary_support is None:
event_binary_support = True
else:
event_binary_support = binary_support
response: BaseResponse = V1Response(
binary_support=event_binary_support,
non_binary_content_type_prefixes=non_binary_prefixes_tuple,
Expand Down

0 comments on commit b1843f9

Please sign in to comment.