Skip to content

Commit b39d619

Browse files
committed
Avoid adding Content-Type to non-body responses
The current code sets the content-type header for all responses to the result's content_type property if upstream does not set a content_type. The default value for content_type is "application/octet-stream". For responses that do not have a body (like 204 No Content or 304 Not Modified), setting a content-type header is unnecessary and potentially misleading. Follow HTTP standards by only adding the content-type header to responses that actually contain a body.
1 parent b903e11 commit b39d619

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

supervisor/api/ingress.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,18 +253,23 @@ async def _handle_request(
253253
skip_auto_headers={hdrs.CONTENT_TYPE},
254254
) as result:
255255
headers = _response_header(result)
256+
257+
# Empty body responses (304, 204, HEAD, etc.) should not be streamed,
258+
# otherwise aiohttp < 3.9.0 may generate an invalid "0\r\n\r\n" chunk
259+
if must_be_empty_body(request.method, result.status):
260+
return web.Response(
261+
headers=headers,
262+
status=result.status,
263+
)
264+
256265
# Avoid parsing content_type in simple cases for better performance
257266
if maybe_content_type := result.headers.get(hdrs.CONTENT_TYPE):
258267
content_type = (maybe_content_type.partition(";"))[0].strip()
259268
else:
260269
content_type = result.content_type
261270
# Simple request
262271
if (
263-
# empty body responses should not be streamed,
264-
# otherwise aiohttp < 3.9.0 may generate
265-
# an invalid "0\r\n\r\n" chunk instead of an empty response.
266-
must_be_empty_body(request.method, result.status)
267-
or hdrs.CONTENT_LENGTH in result.headers
272+
hdrs.CONTENT_LENGTH in result.headers
268273
and int(result.headers.get(hdrs.CONTENT_LENGTH, 0)) < 4_194_000
269274
):
270275
# Return Response

supervisor/docker/addon.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ def ulimits(self) -> list[docker.types.Ulimit] | None:
330330
limits.append(docker.types.Ulimit(name=name, soft=soft, hard=hard))
331331

332332
# Return None if no ulimits are present
333+
_LOGGER.debug("Ulimits for %s: %s", self.addon.slug, limits)
333334
if limits:
334335
return limits
335336
return None

0 commit comments

Comments
 (0)