uvicorn icon indicating copy to clipboard operation
uvicorn copied to clipboard

Idea: Pass a copy of the scope to the ASGI app to prevent headers changing to something incompatible

Open devkral opened this issue 1 year ago • 0 comments

Summary

Checklist

  • [x] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • [ ] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [ ] I've updated the documentation accordingly.

Changes:

The asgi spec allows changing the scope. We rely on headers as list so we copy the scope to the asgi app. Otherwise we can have suddenly headers which are an (exhausted) iterator.

Discussion: #2572 .

I am not sure if this is a good solution. In lilya we copy the scope because of this issue. So please give me guidance in case it doesn't matches your expectations. I can only say: I investigated a sudden crash in lilya and could trace it back to my changes and the expectation that the headers are something like a list in uvicorn. No offense meant, it is just an idea how to fix the root issue.

devkral avatar Feb 05 '25 09:02 devkral