phoenix-wasm: add Conn.to_raw_response/1 for HTTP response serialization#5
Open
phoenix-wasm: add Conn.to_raw_response/1 for HTTP response serialization#5
Conversation
Add the response-side counterpart of to_raw_request/1, completing the full HTTP request/response lifecycle for the WASM pipeline: Raw HTTP request → Conn → middleware/routing → Conn → Raw HTTP response - Conn.to_raw_response/1: converts a Conn's response state (status, resp_headers, resp_body) into a complete HTTP/1.1 response string. Auto-adds Content-Length header. Uses IO lists for zero intermediate string allocations (~1.5µs/op). - Conn.status_reason/1: maps HTTP status codes to standard reason phrases (200 → OK, 404 → Not Found, etc.). Includes 23 tests covering all status codes, content types (JSON, HTML, text), redirects, edge cases, round-trip parsing, and a performance benchmark.
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.
By Sneezy
Summary
Adds
Conn.to_raw_response/1— the response-side counterpart ofto_raw_request/1— completing the full HTTP request/response lifecycle for the WASM pipeline:Changes
Conn.to_raw_response/1Converts a Conn's response state (status, resp_headers, resp_body) into a complete HTTP/1.1 response string:
Content-Lengthheader when not already setConn.status_reason/1Maps HTTP status codes to standard reason phrases:
Covers all common HTTP/1.1 status codes (1xx through 5xx).
Tests
23 new tests covering: