Skip to content

Commit

Permalink
Ensure hassio does not do blocking I/O to get forwarded host
Browse files Browse the repository at this point in the history
request.host can fallback to doing blocking I/O because of
aio-libs/aiohttp#9308
  • Loading branch information
bdraco committed Sep 27, 2024
1 parent fb0e102 commit ea726e1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions homeassistant/components/hassio/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,17 @@ def _init_header(request: web.Request, token: str) -> CIMultiDict | dict[str, st
headers[hdrs.X_FORWARDED_FOR] = _forwarded_for_header(forward_for, peername[0])

# Set X-Forwarded-Host
if not (forward_host := request.headers.get(hdrs.X_FORWARDED_HOST)):
forward_host = request.host
headers[hdrs.X_FORWARDED_HOST] = forward_host
# Avoid calling request.host as it can fallback to doing blocking DNS lookups
# https://github.com/aio-libs/aiohttp/issues/9308
if forward_host := request.headers.get(
hdrs.X_FORWARDED_HOST
) or request.headers.get(hdrs.HOST):
headers[hdrs.X_FORWARDED_HOST] = forward_host

# Set X-Forwarded-Proto
forward_proto = request.headers.get(hdrs.X_FORWARDED_PROTO)
if not forward_proto:
forward_proto = request.scheme
headers[hdrs.X_FORWARDED_PROTO] = forward_proto
headers[hdrs.X_FORWARDED_PROTO] = (
request.headers.get(hdrs.X_FORWARDED_PROTO) or request.scheme
)

return headers

Expand Down

0 comments on commit ea726e1

Please sign in to comment.