Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DM-40656] Fix bug where "Response content shorter than Content-Length"
When serving a file that should be cached on the other side (and crawlspace returns a 304) we return the Content-Length of the cached file instead of the Content-Length of the 304 message. This makes python emit the following error: INFO: 68.230.27.252:40976 - "GET /api/hips/images/band_z/Norder11/Dir35540000/Npix35543833.png HTTP/1.1" 304 Not Modified ERROR: Exception in ASGI application Traceback (most recent call last): File "/opt/venv/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 419, in run_asgi result = await app( # type: ignore[func-returns-value] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__ return await self.app(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/venv/lib/python3.11/site-packages/fastapi/applications.py", line 270, in __call__ await super().__call__(scope, receive, send) File "/opt/venv/lib/python3.11/site-packages/starlette/applications.py", line 124, in __call__ await self.middleware_stack(scope, receive, send) File "/opt/venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 184, in __call__ raise exc File "/opt/venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 162, in __call__ await self.app(scope, receive, _send) File "/opt/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 107, in __call__ await response(scope, receive, send) File "/opt/venv/lib/python3.11/site-packages/starlette/responses.py", line 266, in __call__ async with anyio.create_task_group() as task_group: File "/opt/venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 662, in __aexit__ raise exceptions[0] File "/opt/venv/lib/python3.11/site-packages/starlette/responses.py", line 269, in wrap await func() File "/opt/venv/lib/python3.11/site-packages/starlette/responses.py", line 263, in stream_response await send({"type": "http.response.body", "body": b"", "more_body": False}) File "/opt/venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 159, in _send await send(message) File "/opt/venv/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 561, in send raise RuntimeError("Response content shorter than Content-Length") RuntimeError: Response content shorter than Content-Length Looking through the spec a bit more, it seems like it's okay to not provide a content length and I think actually encouraged https://datatracker.ietf.org/doc/html/rfc7232#section-4.1
- Loading branch information