Skip to content

chore: expose HTTP accept primitives#193

Merged
richard-ramos merged 1 commit into
mainfrom
expose-api
May 6, 2026
Merged

chore: expose HTTP accept primitives#193
richard-ramos merged 1 commit into
mainfrom
expose-api

Conversation

@richard-ramos
Copy link
Copy Markdown
Member

Adds the minimal API needed by nim-libp2p to avoid head-of-line blocking on slow or malformed WebSocket handshakes.

Adds the minimal API needed by nim-libp2p to avoid head-of-line blocking on slow or malformed WebSocket handshakes.
@richard-ramos richard-ramos changed the title chore: expose HTTP accept primitives for concurrent ws handshakes chore: expose HTTP accept primitives Apr 28, 2026
@richard-ramos richard-ramos marked this pull request as ready for review April 28, 2026 18:38
Copilot AI review requested due to automatic review settings April 28, 2026 18:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR exposes lower-level HTTP accept primitives in websock/http/server.nim so downstream consumers (e.g., nim-libp2p) can accept a connection/stream and control how/when the HTTP request is read, helping avoid head-of-line blocking from slow or malformed WebSocket handshakes.

Changes:

  • Exported readHttpRequest so it can be used externally.
  • Added acceptStream* to accept a connection and return an AsyncStream without reading the HTTP request.
  • Refactored accept* to call acceptStream* and then readHttpRequest.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread websock/http/server.nim
Comment on lines 145 to +146
trace "Got new request", isTls = server.secure
stream
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acceptStream logs "Got new request", but at this point no HTTP request has been read yet (only the transport has been accepted and wrapped in an AsyncStream). This can be misleading in production diagnostics; consider changing it to "Got new connection/stream" or moving the log to accept after readHttpRequest succeeds.

Copilot uses AI. Check for mistakes.
Comment thread websock/http/server.nim
Comment on lines +132 to 133
proc acceptStream*(server: HttpServer): Future[AsyncStream] {.async.} =
if not isNil(server.handler):
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New public APIs acceptStream* and readHttpRequest* are introduced/refactored here, but there are no tests covering the accept-style flow (and specifically acceptStream). Adding an async test that accepts a connection via acceptStream, parses it via readHttpRequest, and completes a basic WebSocket handshake would help prevent regressions and validate the intended head-of-line blocking mitigation.

Copilot uses AI. Check for mistakes.
@richard-ramos richard-ramos merged commit 72d4e57 into main May 6, 2026
38 checks passed
@richard-ramos richard-ramos deleted the expose-api branch May 6, 2026 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants