Skip to content

Add support for HTTP listeners - #52

Merged
snelusha merged 5 commits into
mainfrom
feat/http-listener
Aug 6, 2026
Merged

Add support for HTTP listeners#52
snelusha merged 5 commits into
mainfrom
feat/http-listener

Conversation

@snelusha

@snelusha snelusha commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Resolves #38

Summary by CodeRabbit

  • New Features
    • Added HTTP listener support for WebAssembly applications.
    • Added request dispatching across supported HTTP methods, including headers, query parameters, and request bodies.
    • Added graceful and immediate listener shutdown options.
    • Added listener readiness notifications and HTTP dispatch APIs.
  • Bug Fixes
    • Improved error handling for unavailable transports, invalid configurations, missing routes, and request failures.
  • Tests
    • Added integration coverage for listener startup, routing, responses, and shutdown.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@snelusha, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 57 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fcae687f-7fa7-481e-96ff-fb045058148e

📥 Commits

Reviewing files that changed from the base of the PR and between 45a2257 and ee97870.

📒 Files selected for processing (16)
  • packages/ballerina-wasm/ballerina
  • packages/ballerina-wasm/diagnostic_printer.go
  • packages/ballerina-wasm/http_dispatch_wasm.go
  • packages/ballerina-wasm/listeners_wasm.go
  • packages/ballerina-wasm/main_wasm.go
  • packages/ballerina-wasm/pal_wasm.go
  • packages/ballerina-wasm/run_context_wasm.go
  • packages/balrun/src/ballerina-core.ts
  • packages/balrun/src/ballerina.ts
  • packages/balrun/src/http-listener.ts
  • packages/balrun/src/index.ts
  • packages/balrun/src/wasm-bridge.ts
  • packages/balrun/src/wasm.d.ts
  • packages/balrun/tests/ballerina.test.ts
  • packages/balrun/tests/fixtures/http-listener.bal
  • packages/balrun/tests/wasm-bridge.test.ts
📝 Walkthrough

Walkthrough

The change adds Node-based HTTP listener support across the Ballerina runtime, WASM bridge, and public API. It registers listeners, dispatches requests asynchronously, converts headers and bodies, supports lifecycle operations, and adds end-to-end tests.

Changes

HTTP listener integration

Layer / File(s) Summary
HTTP transport and contracts
packages/balrun/src/http-listener.ts, packages/balrun/src/index.ts
Defines HTTP listener types and implements Node server creation, request conversion, host and path matching, dispatch, response writing, and graceful or immediate shutdown.
WASM listener runtime
packages/ballerina-wasm/*
Registers HTTP handlers, starts listeners through the JavaScript transport, dispatches requests asynchronously, converts request and response data, and clears handler state during shutdown.
Bridge and public API wiring
packages/balrun/src/ballerina-core.ts, packages/balrun/src/ballerina.ts, packages/balrun/src/wasm-bridge.ts, packages/balrun/src/wasm.d.ts, packages/balrun/tests/ballerina.test.ts
Adds listener readiness callbacks, platform transport options, HTTP dispatch methods, WASM declarations, and test-core support.
HTTP listener validation
packages/balrun/tests/fixtures/http-listener.bal, packages/balrun/tests/wasm-bridge.test.ts
Adds HTTP resources and tests for listener readiness, methods, headers, queries, request bodies, missing routes, shutdown, oversized bodies, and exit status.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant NodeHTTPTransport
  participant WasmBridge
  participant BallerinaWASM
  Client->>NodeHTTPTransport: Send HTTP request
  NodeHTTPTransport->>WasmBridge: Dispatch normalized request
  WasmBridge->>BallerinaWASM: Call dispatchHttpRequest
  BallerinaWASM-->>WasmBridge: Return status, headers, and body
  WasmBridge-->>NodeHTTPTransport: Return HTTP response
  NodeHTTPTransport-->>Client: Write HTTP response
Loading

Possibly related issues

Possibly related PRs

  • snelusha/balrun#16: Introduced the WASM bridge and core interfaces extended by this HTTP dispatch integration.
  • snelusha/balrun#48: Modified the runtime lifecycle and core APIs used by this listener integration.
  • snelusha/balrun#10: Added asynchronous WASM Promise infrastructure used by the dispatch flow.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The diagnostic formatting-only change is unrelated to the HTTP listener objective in issue #38. Remove the unrelated formatting change or document why it is required for HTTP listener support.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: adding HTTP listener support.
Linked Issues check ✅ Passed The implementation and tests satisfy the HTTP listener support objective described in issue #38.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/http-listener

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@snelusha
snelusha force-pushed the feat/http-listener branch from 4b37c84 to 99ebc27 Compare August 5, 2026 23:27
@snelusha
snelusha force-pushed the feat/http-listener branch from 99ebc27 to c9d2791 Compare August 5, 2026 23:29
Base automatically changed from feat/file-read-write to main August 5, 2026 23:33
@snelusha
snelusha force-pushed the feat/http-listener branch from c9d2791 to cf40dd4 Compare August 5, 2026 23:33
@snelusha
snelusha force-pushed the feat/http-listener branch from cf40dd4 to af55274 Compare August 6, 2026 21:41

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ballerina-wasm/ballerina`:
- Line 1: Update the tracked ballerina submodule pointer in the parent
repository to commit 1858993886be3200dc9a17169da4526320f02a9a, ensure that
commit is available in the submodule repository, and push the corrected pointer
before merging.

In `@packages/balrun/src/http-listener.ts`:
- Around line 95-104: The listener record in
packages/balrun/src/http-listener.ts lines 95-104 must remain registered until
close(listener.server) resolves; move listeners.delete after the awaited close,
while preserving immediate socket destruction. In
packages/ballerina-wasm/listeners_wasm.go lines 27-31, return the transport
close error before calling activeRunContext.unregisterHandler so handler state
remains on failure; do not add an explicit closing state unless required by the
existing dispatch behavior.
- Around line 225-235: Update readBody to enforce a finite listener request-body
limit while reading, stopping accumulation as soon as the limit is exceeded and
signaling that condition to the HTTP handler. In the surrounding request
handling flow, translate that signal into HTTP 413, while preserving normal body
parsing for requests within the limit.

In `@packages/balrun/src/wasm-bridge.ts`:
- Around line 67-74: Update WasmBridge.run to prevent concurrent executions from
sharing or overwriting the instance-level onListenerReady callback: reject a new
invocation while a run is active, preserving the existing empty-path validation
and cleanup behavior, and ensure the active-run state is reset when the promise
settles.

In `@packages/balrun/tests/fixtures/http-listener.bal`:
- Around line 17-20: Update the inspect resource function to read the name query
parameter using request.getQueryParamValue("name") instead of request.rawPath,
and include that value in the response while preserving the existing header
behavior. Update the corresponding shared expected response in the wasm bridge
test to match the query-based output.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 23d60d1b-7d38-4792-ab6b-154bb5e41c25

📥 Commits

Reviewing files that changed from the base of the PR and between 45a2257 and af55274.

📒 Files selected for processing (16)
  • packages/ballerina-wasm/ballerina
  • packages/ballerina-wasm/diagnostic_printer.go
  • packages/ballerina-wasm/http_dispatch_wasm.go
  • packages/ballerina-wasm/listeners_wasm.go
  • packages/ballerina-wasm/main_wasm.go
  • packages/ballerina-wasm/pal_wasm.go
  • packages/ballerina-wasm/run_context_wasm.go
  • packages/balrun/src/ballerina-core.ts
  • packages/balrun/src/ballerina.ts
  • packages/balrun/src/http-listener.ts
  • packages/balrun/src/index.ts
  • packages/balrun/src/wasm-bridge.ts
  • packages/balrun/src/wasm.d.ts
  • packages/balrun/tests/ballerina.test.ts
  • packages/balrun/tests/fixtures/http-listener.bal
  • packages/balrun/tests/wasm-bridge.test.ts

Comment thread packages/ballerina-wasm/ballerina
Comment thread packages/balrun/src/http-listener.ts
Comment thread packages/balrun/src/http-listener.ts Outdated
Comment thread packages/balrun/src/wasm-bridge.ts
Comment thread packages/balrun/tests/fixtures/http-listener.bal
@snelusha
snelusha force-pushed the feat/http-listener branch from 6ddaa92 to ee97870 Compare August 6, 2026 22:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/balrun/tests/wasm-bridge.test.ts`:
- Around line 91-93: Update the rejection assertion for isolatedBridge.run in
the relevant test to await the promise returned by
expect(...).rejects.toThrow(), ensuring the assertion completes within the test
scope and preserves the expected error message.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 31fcfa70-435c-481e-bd74-b496e089237b

📥 Commits

Reviewing files that changed from the base of the PR and between af55274 and 6ddaa92.

📒 Files selected for processing (5)
  • packages/ballerina-wasm/listeners_wasm.go
  • packages/balrun/src/http-listener.ts
  • packages/balrun/src/wasm-bridge.ts
  • packages/balrun/tests/fixtures/http-listener.bal
  • packages/balrun/tests/wasm-bridge.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/balrun/tests/fixtures/http-listener.bal
  • packages/ballerina-wasm/listeners_wasm.go

Comment thread packages/balrun/tests/wasm-bridge.test.ts
@snelusha
snelusha merged commit 06808dd into main Aug 6, 2026
1 check passed
@snelusha
snelusha deleted the feat/http-listener branch August 6, 2026 23:00
This was referenced Aug 7, 2026
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.

Add support for HTTP listeners

1 participant