Repository navigation
Conversation
Response writes HTTP/1.x straight to the connection, which leaves an HTTP/2 engine no way to reuse the router, middleware and handlers. - Sink (src/sink.zig): head, interim (100 Continue), body writer, end with trailers, writeError, peerGone. - Response.initSink: a response whose head, body bytes and end go to a sink; Response.trailer for trailer fields; Response.peerGone. The HTTP/1.x paths are unchanged. - Request.body_source: a body that arrives unframed (HTTP/2 DATA), decoded like any other; Request.applyEntityHeaders, factored out of the parser. - Server.dispatch: routes a request through the middleware to its handler, for an engine with its own request loop.
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 4 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
The
h2-enginesketch (#137) notes it is blocked on a protocol-neutral Response backend. This is a proposal for that seam, kept additive so the HTTP/1.x paths and the ~100 tests that build aResponseover aConnectionare untouched.Response
Sink(newsrc/sink.zig):head(status, headers, content_length),interim(status)for 100 Continue,body()writer for unframed bytes,end(trailers),writeError()andpeerGone().Response.initSink(arena, io, sink, max_headers). With a sink,sendHeaderhands over the head instead of printing a status line,streamsets neither chunked nor the HTTP/1.0 mode (the protocol frames), body bytes go tosink.body(), and the end of the message issink.end(trailers)(fromwrite,sendBody, the file path andStreamingBodyWriter.end).resolveasks the sink for the cause of a failed write.Response.trailer(name, value): trailer fields, carried by a sink (gRPC status over HTTP/2); dropped over HTTP/1.x.Response.peerGone(), used by the middleware executor instead ofres.conn.peerGone().upgradeWebSocketreturns null on a sink (HTTP/2 has RFC 8441 instead).Response.ioreplacesconn.iofor files.Request
Request.body_source: ?BodySource(reader + error accessor).BodyReader.streamFramedreads from it when set, so content decoding,body(), forms and multipart work unchanged. 100 Continue goes throughsink.interimwhen the response has a sink.Request.applyEntityHeaders(), factored out of the parser'sonHeadersComplete, so an engine fillscontent_type/content_encoding/content_lengththe same way.Server
Server.dispatch(req, res): router lookup (400 for an unparseable URL) and the middleware executor, for an engine with its own request loop.handleRequestsis not changed to use it, to keep this diff small.Tests: six
Response sinktests (buffered body with length, streamed body unframed and ended once, trailers, HEAD, 204, no WebSocket upgrade), three forRequest(body source, gzip through a body source, 100 Continue through the sink), andServer.dispatchrouting a request over a sink through the middleware to a handler that sets a trailer../check.shpasses on 0.16; build and tests pass on 0.17.I'm using this from an nghttp2 server engine in my fork; happy to reshape the seam to whatever fits the design you have in mind for #137.