Skip to content

binary http body: bodyBytes(), Buffer.from base64, serveFile, remove body size limit#94

Merged
cs01 merged 12 commits intomainfrom
bump-body-limit
Mar 5, 2026
Merged

binary http body: bodyBytes(), Buffer.from base64, serveFile, remove body size limit#94
cs01 merged 12 commits intomainfrom
bump-body-limit

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 5, 2026

Summary

  • Binary HTTP body support: c.req.bodyBytes() returns a Uint8Array of the raw request body, enabling binary upload handling (images, files, etc.)
  • Uint8Array.fromRawBytes(str, len): new built-in that wraps a raw C string + length into a Uint8Array without null-termination assumptions
  • Buffer.from(str, 'base64'): new base64 decode built-in backed by base64-bridge.c, returns a Uint8Array
  • bytesResponse(data, status, headers): new codegen primitive that constructs a binary HttpResponse from a Uint8Array
  • c.bytes(data, contentType): new Context method for returning binary responses (implemented in ChadScript on top of bytesResponse)
  • serveFile(path, contentType): serve a file from disk; imported from chadscript/http, implemented in ChadScript on top of fs.readFileSync + bytesResponse
  • Remove 1 MB body cap: lws-bridge now mallocs exactly Content-Length bytes; large bodies (multi-MB uploads) now receive fully
  • Fix chunked read buffer: reset data_len after each chunk so subsequent TCP segments are placed at offset 0 — fixes truncated large-body reads
  • Fix body_len type: changed from int64_t to double in the bridge request struct so ChadScript reads it correctly as a number
  • Fix router method matching: same-path routes with different HTTP methods now match the correct handler
  • Fix closure analyzer: method_call, call, and await statement node types were missing from the closure mutation checker, causing false negatives
  • CI: base64-bridge.o and time-bridge.o are now both included in release artifact packaging and vendor verification

Test plan

  • POST a request with a body > 1 MB and verify it arrives complete via c.req.bodyBytes()
  • Upload a PNG/binary file and round-trip it through bodyBytes()Buffer.from(..., 'base64') → decode
  • serveFile() serves a static binary file with correct Content-Type
  • c.bytes() returns a binary response with correct headers and body length
  • Routes GET /foo and POST /foo both match their respective handlers
  • npm run verify passes (all unit tests + self-hosting)

@cs01 cs01 changed the title binary http body support: dynamic malloc, Uint8Array.fromRawBytes, Bu… binary http body: bodyBytes(), Buffer.from base64, serveFile, remove body size limit Mar 5, 2026
@cs01 cs01 force-pushed the bump-body-limit branch from 90d5683 to 2b47e2a Compare March 5, 2026 19:36
@cs01 cs01 merged commit 9cdb56e into main Mar 5, 2026
12 checks passed
@cs01 cs01 deleted the bump-body-limit branch March 5, 2026 19:46
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