Skip to content

HTTP server: read a request until the end of its headers - #2302

Open
rfaman wants to merge 1 commit into
openshwprojects:mainfrom
rfaman:http-read-whole-request
Open

rfaman wants to merge 1 commit into
openshwprojects:mainfrom
rfaman:http-read-whole-request

Conversation

@rfaman

@rfaman rfaman commented Nov 9, 2026 •

Copy link
Copy Markdown

Both HTTP servers stopped reading as soon as recv returned less than the free space, that is after the first TCP segment. A request larger than one segment (about 1460 bytes on a LAN, less through a VPN) was parsed truncated ("invalid request") and the connection closed without a response. Details in #2303.

  • Keep reading until the end of the headers (CRLF CRLF, RFC 9112). POST bodies (/api/ota, /api/lfs/) are still read by their handler, as before.
  • http_tcp_server.c (the server built for BK7231N/T) now sets a 30 s SO_RCVTIMEO on accepted sockets, as new_tcp_server.c already does, so a silent client cannot hold the thread.

Measured on http_tcp_server.c on a CB3S (BK7231N) through a WireGuard tunnel (MTU 1360), GET commands of 1400 to 3000 characters: 18 failures out of 210 at 1400 characters before, 0 out of 1597 after (together with the SDK realloc fix of the same issue). The change in new_tcp_server.c is the same loop but is not tested on hardware. Builds for BK7231N and BK7231T.

Done with the help of Claude (Anthropic).

Both servers stopped reading after the first TCP segment, so a request larger than one segment was parsed
truncated. Keep reading until CRLF CRLF (RFC 9112); POST bodies are still read by their handler.
http_tcp_server.c also sets a 30 s SO_RCVTIMEO on accepted sockets, as new_tcp_server.c does.

Co-authored-by: Claude <noreply@anthropic.com>
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.

1 participant