feat: pass through fastapi.Response returns unchanged#5
Merged
Conversation
When a wrapped function returns a `fastapi.Response` (or any subclass — StreamingResponse, FileResponse, PlainTextResponse, etc.), the endpoint now returns it verbatim instead of trying to JSON-encode it. This lets qh-built apps emit non-JSON payloads (PDFs, file downloads, streams) without bypassing qh — reelee's chunk-9 PDF export is the first customer. Tests: 2 new in test_mk_app.py (Response with custom headers + bytes, StreamingResponse from a generator). 136 / 136 total.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a wrapped function returns a
fastapi.Response(or any subclass —StreamingResponse,FileResponse,PlainTextResponse, etc.), the endpoint now returns it verbatim instead of trying to JSON-encode it.Why
Lets qh-built apps emit non-JSON payloads (PDFs, file downloads, streams) without bypassing qh and hand-rolling FastAPI routes. The reelee project is the first customer (chunk 9: PDF export from a wrapped Python function).
What changed
qh/endpoint.py— single isinstance check before the default JSON encoding step.qh/tests/test_mk_app.py— 2 new tests:Responsewith customcontent-disposition+ bytes body.StreamingResponsedriven by a generator.Verify
python3 -m pytest qh/ -q— 136 / 136 green.