Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DM-40656] Update dependencies / fix a bug #81

Merged
merged 5 commits into from
Sep 7, 2023
Merged

Conversation

cbanek
Copy link
Contributor

@cbanek cbanek commented Sep 5, 2023

No description provided.

@cbanek cbanek changed the title [DM-40656] Fix up dependencies [DM-40656] Update dependencies Sep 5, 2023
@cbanek cbanek requested a review from rra September 6, 2023 00:09
@cbanek cbanek changed the title [DM-40656] Update dependencies [DM-40656] Update dependencies / fix a bug Sep 6, 2023
@cbanek
Copy link
Contributor Author

cbanek commented Sep 6, 2023

I'm not so sure about the content length of a 304... maybe I should just delete that header? It is true what that error message says. Although looking just now says that it should send what the body would have been? But then it seems like the framework would know better? Open to any thoughts on that one

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
Copy link
Member

@rra rra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for the fix. Yeah, setting Content-Length in the 304 empty response is definitely wrong.

@cbanek cbanek merged commit f51e3ad into main Sep 7, 2023
3 checks passed
@cbanek cbanek deleted the tickets/DM-40656 branch September 7, 2023 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants