-
Notifications
You must be signed in to change notification settings - Fork 21
chore: expose HTTP accept primitives #193
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ template used(x: typed) = | |
| # silence unused warning | ||
| discard | ||
|
|
||
| proc readHttpRequest( | ||
| proc readHttpRequest*( | ||
| stream: AsyncStream, headersTimeout: Duration | ||
| ): Future[HttpRequest] {. | ||
| async: (raises: [CancelledError, AsyncStreamError, HttpError]) | ||
|
|
@@ -129,9 +129,7 @@ proc handleConnCb( | |
| finally: | ||
| await stream.closeWait() | ||
|
|
||
| # TODO async raises not implemented for accept because it breaks libp2p (1.13.0 | ||
| # at the time of writing) | ||
| proc accept*(server: HttpServer): Future[HttpRequest] {.async.} = | ||
| proc acceptStream*(server: HttpServer): Future[AsyncStream] {.async.} = | ||
| if not isNil(server.handler): | ||
| raise newException( | ||
| HttpError, "Callback already registered - cannot mix callback and accepts styles!" | ||
|
|
@@ -145,6 +143,13 @@ proc accept*(server: HttpServer): Future[HttpRequest] {.async.} = | |
| raise (ref HttpError)(msg: error) | ||
|
|
||
| trace "Got new request", isTls = server.secure | ||
| stream | ||
|
Comment on lines
145
to
+146
|
||
|
|
||
| # TODO async raises not implemented for accept because it breaks libp2p (1.13.0 | ||
| # at the time of writing) | ||
| proc accept*(server: HttpServer): Future[HttpRequest] {.async.} = | ||
| let stream = await server.acceptStream() | ||
|
|
||
| try: | ||
| await stream.readHttpRequest(server.headersTimeout) | ||
| except CancelledError as exc: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New public APIs
acceptStream*andreadHttpRequest*are introduced/refactored here, but there are no tests covering the accept-style flow (and specificallyacceptStream). Adding an async test that accepts a connection viaacceptStream, parses it viareadHttpRequest, and completes a basic WebSocket handshake would help prevent regressions and validate the intended head-of-line blocking mitigation.