Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ holds only what is specific to wasi.
built with exceptions on wasip2 and wasip3, as the superproject's Jamroot
builds any; wasmtime serves both with no flag beyond those of
`webcpp.serve`. An exception that escapes the main on either traps the
instance, and wasmtime 47 answers its own HTML 500 and keeps serving: the
instance, and wasmtime 50.0.1 answers its own HTML 500 and keeps serving: the
page and the main's Doc Comment say so. The handler catches nothing, by
the owner's decision; the host answers.
- **`config.hpp` comes first.** Every public header includes
Expand All @@ -60,7 +60,7 @@ holds only what is specific to wasi.
else `PATH`); the `wasi:http` WIT of WASI 0.2.12 and 0.3.0, the `wit/deps`
directories of the Rust crates `wasip2` 1.0.4 and `wasip3` 0.9.0
(`-sWASI_WIT_P2=<dir>` and `-sWASI_WIT_P3=<dir>`, else
`.local/wasi-wit/p2` and `.local/wasi-wit/p3`); wasmtime 47.0.3
`.local/wasi-wit/p2` and `.local/wasi-wit/p3`); wasmtime 50.0.1
(`-sWASMTIME=<path>`, else `PATH`), looked for only when a served test
runs. A native build needs none of them.
- **Served tests.** A program that answers HTTP is tested with
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ request, calls your main and writes the answer back. It covers WASI 0.2

Requirements: C++20, wasi-sdk 34, wit-bindgen's C generator (0.62.0
measured), the `wasi:http` WIT of your target, and a host such as wasmtime
(47.0.3 measured). The headers include only the standard library and the
(50.0.1 measured). The headers include only the standard library and the
bindings wit-bindgen writes. The helper needs neither exceptions nor RTTI
and imposes neither: webcpp builds it with exceptions on wasip2 and wasip3,
where an exception that escapes your main traps the instance (see
Expand All @@ -43,7 +43,7 @@ where an exception that escapes your main traps the instance (see
A component that greets whoever calls it, built by hand with wasi-sdk. These
are the exact files and commands, which webcpp's test `by_hand` runs in the
lane `http` of `example/`, on wasip2 and on wasip3, with wasi-sdk 34,
wit-bindgen 0.62.0 and wasmtime 47.0.3
wit-bindgen 0.62.0 and wasmtime 50.0.1
([example/by_hand/build.sh](example/by_hand/build.sh)).

`wit/world.wit`, the world your component exports (name it as you like):
Expand Down Expand Up @@ -176,7 +176,7 @@ library, Boost.URL's `parse_origin_form` for example.

The handler catches nothing. On wasip2 and wasip3, where webcpp builds a
program with exceptions, an exception that escapes your main traps the
instance: wasmtime 47 prints the trap on its standard error, `thrown Wasm
instance: wasmtime 50.0.1 prints the trap on its standard error, `thrown Wasm
exception`, and answers the client with its own `500 Internal Server Error`,
an HTML page, then serves the requests after it.

Expand All @@ -199,7 +199,7 @@ struct of three members:

| Member | Type | What it holds |
| --- | --- | --- |
| `status` | `unsigned`, 200 by default | the status, sent as it is within 100 to 599; outside them the handler answers an internal error instead, which wasmtime 47 sends as its own `500 Internal Server Error` |
| `status` | `unsigned`, 200 by default | the status, sent as it is within 100 to 599; outside them the handler answers an internal error instead, which wasmtime 50.0.1 sends as its own `500 Internal Server Error` |
| `content_type` | `std::string_view`, empty by default | the `content-type` header, sent only when not empty; read after your main returns, so it views a literal, like `"application/json"`, or the method or the target, never a string of your main's own; one the host refuses, with a CR, an LF or a NUL for example, answers an internal error instead |
| `body` | `std::string`, empty by default | the body, sent whole, however long |

Expand All @@ -220,7 +220,7 @@ itself:
| the bindings generated with `--rename-world webcpp_wasi_http` | the header includes `webcpp_wasi_http.h` and uses the names wit-bindgen gives the world, `webcpp_wasi_http_string_t` and the like; renaming makes them the same in every project, whatever its world is called |
| `webcpp_wasi_http.c` compiled as C for the target, and `webcpp_wasi_http_component_type.o`, linked | the glue that calls your handler, and the world's type information for the component linker |
| the directory of the bindings on the include path | for `webcpp_wasi_http.h` |
| `-mexec-model=reactor` on the link | the program is a reactor: it exports a handler and has no C `main`; wasmtime 47 also serves it linked as a command, but webcpp builds and tests reactors |
| `-mexec-model=reactor` on the link | the program is a reactor: it exports a handler and has no C `main`; wasmtime 50.0.1 also serves it linked as a command, but webcpp builds and tests reactors |

The host has its part too: `wasmtime serve` runs a component of wasi with
`-S cli`, since wasi-libc imports parts of `wasi:cli`, and on wasip3 with
Expand Down
10 changes: 10 additions & 0 deletions build.jam
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ alias http-bindings : http-bindings-p2 http-bindings-p3 ;
alias http : : : : <library>wasi <library>http-bindings
<toolset>clang-wasip2:<define>WEBCPP_WASI_HTTP_P2
<toolset>clang-wasip3:<define>WEBCPP_WASI_HTTP_P3 ;

# Complete host messages use the host client, never a guest socket reactor.
webcpp.wit-bindings host-http-bindings-p2 : wit/host-http-p2.wit : http : webcpp_wasi_http : p2 ;
webcpp.wit-bindings host-http-bindings-p3 : wit/host-http-p3.wit : http : webcpp_wasi_http : p3
: --async "wasi:http/handler@0.3.0#handle" --async "wasi:http/client@0.3.0#send"
--async "wasi:clocks/monotonic-clock@0.3.0#wait-until" ;
alias host-http-bindings : host-http-bindings-p2 host-http-bindings-p3 ;
alias host-http : : : : <library>wasi <library>host-http-bindings
<toolset>clang-wasip2:<define>WEBCPP_WASI_HTTP_P2
<toolset>clang-wasip3:<define>WEBCPP_WASI_HTTP_P3 ;
4 changes: 2 additions & 2 deletions doc/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ webcpp.doc wasi : wasi.adoc ;
# with the bindings of wasip2 and the macro of that version; the Doc Comments
# of its wasip3 branch are checked too, with the bindings and the macro of
# wasip3.
webcpp.reference wasi : <library>/webcpp/wasi//http-bindings-p2-headers
webcpp.reference wasi : <library>/webcpp/wasi//host-http-bindings-p2-headers
<define>WEBCPP_WASI_HTTP_P2
: <library>/webcpp/wasi//http-bindings-p3-headers <define>WEBCPP_WASI_HTTP_P3 ;
: <library>/webcpp/wasi//host-http-bindings-p3-headers <define>WEBCPP_WASI_HTTP_P3 ;
2 changes: 1 addition & 1 deletion doc/boost.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ given `-W exceptions=y`; jco, whose `jco transpile` is given
`--bindgen-enable-wasm-exnref`; or another engine of WebAssembly 3.0.

wasi's handler catches nothing: an exception that escapes the main traps the
instance, and wasmtime 47 answers the client with its own
instance, and wasmtime 50.0.1 answers the client with its own
`500 Internal Server Error` (<<wasi-main-rules>>). A main that may throw
catches what it can answer itself.

Expand Down
4 changes: 2 additions & 2 deletions doc/build.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ version of WASI it is built for. A build provides it with these:

| `-mexec-model=reactor` on the link
| The program is a reactor: it exports a handler and has no C `main`.
wasmtime 47 also serves the same program linked without it, as a
command, but webcpp builds and tests reactors.
Historical tests with wasmtime 47 also served the same program linked
without it, as a command. Current webcpp builds and tests reactors.
|===

The host has its part too: `wasmtime serve` runs a component of wasi with
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ of every version are on webcpp's index page.
=== webcpp 0.1.0

// tag::0.1.0[]
* Updated Wasmtime instructions to 50.0.1, preserving historical measurements.
* Fixed a status outside 100-599 answering 200 OK; it now answers an
internal error.
* Fixed a content type viewing the request's method or target not being
Expand Down
9 changes: 5 additions & 4 deletions doc/guarantees.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ is read; and by `response`, which checks that the body is a copy.
chunks of at most 4096 bytes, the most `blocking-write-and-flush` takes; on
wasip3 by writing until the stream has taken every byte. _Held by_
`http_long_body`, whose body of three chunks and some bytes more arrives
whole, on wasip2 and on wasip3. wasmtime 47 takes the whole body in one write
on wasip3, a body of 1{nbsp}MiB too, so it never makes the loop of wasip3 take
a second turn: the test fails there when a write is cut short, and the loop
stands for a host that takes less per write.
whole, on wasip2 and on wasip3. Historical tests with wasmtime 47 took the
whole body in one write on wasip3, a body of 1{nbsp}MiB too. The regression
with wasmtime 50.0.1 verifies complete delivery, not the number of writes.
The loop stands for a host that takes less per write; the test fails when
a write is cut short and the remaining bytes are not sent.
. [[wasi-invariant-5]]*On wasip3, the handler never resumes in its callback.*
It waits inside the task for every write that blocks, and always ends with
`EXIT`, because context slot 0 belongs to wasi-libc on wasip3: using it
Expand Down
2 changes: 1 addition & 1 deletion doc/introduction.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bindings are generated: <<wasi-build-by-hand>> shows the commands.
* *wit-bindgen's C generator,* 0.62.0 measured, and the `wasi:http` WIT of
the target: the `wit/deps` directory of the Rust crate `wasip2` 1.0.4 for
WASI 0.2.12, or of `wasip3` 0.9.0 for WASI 0.3.0.
* *A host of `wasi:http`,* such as wasmtime, 47.0.3 measured.
* *A host of `wasi:http`,* such as wasmtime, 50.0.1 measured.
* *Nothing else.* The headers include only the standard library and the
bindings wit-bindgen writes, and need no Boost. They throw, try and catch
nothing, and use no RTTI: wasi needs neither exceptions nor RTTI, and
Expand Down
7 changes: 3 additions & 4 deletions doc/limits.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
[#wasi-limits]
== Limits

The handler hands the main only the method and the target. It reads no
The original main-macro handler hands the main only the method and the target. It reads no
request header and no request body, and sends no response header but
`content-type`. A main that needs a request's body or its headers, or to set
other headers, waits for the handler to grow: today it cannot be written with
wasi.
`content-type`. Use the <<wasi-host-messages,complete host-message API>> for a request body,
additional fields, trailers or an outgoing host request.

[#wasi-limits-allocation]
=== What it allocates
Expand Down
2 changes: 1 addition & 1 deletion doc/main.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ each request, and sends what it returns.
* *An exception that escapes it is not caught.* The handler catches
nothing, so on wasip2 and wasip3, where webcpp builds a program with
exceptions, an exception that escapes the main traps the instance, and the
response is never sent. wasmtime 47 then prints the trap and its backtrace
response is never sent. wasmtime 50.0.1 then prints the trap and its backtrace
on its standard error, `thrown Wasm exception` among them, and answers the
client with its own `500 Internal Server Error`, the HTML page it answers
an internal error with; it serves the requests after it.
Expand Down
84 changes: 84 additions & 0 deletions doc/messages.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) 2026 WebCpp.org
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)

[#wasi-host-messages]
== Complete host messages and streams

Select `/webcpp/wasi//host-http` and include
`<webcpp/wasi/http/host.hpp>` for incoming and outgoing HTTP with exposed
fields, bodies and trailers. This profile imports `wasi:http/outgoing-handler`
on P2 and `wasi:http/client` on P3, as well as the monotonic clock used for
transfer deadlines. It does not require a guest TCP reactor or guest TLS.
The existing `/webcpp/wasi//http` profile and main macros remain available.

`incoming_request` owns the host request. Read `method()`, `target()`,
`authority()` and `headers()` before `consume(error)`. A `body_reader` reads
into caller-owned spans, enforces `transfer_options::body_limit`, and reports
EOF separately from successful completion. After EOF, call `finish` to
check the completion result and visit the trailers. On P2 the request or
response owner must outlive its body reader. On P3 consuming the body moves
the request or response and retains its completion future in the reader.

`commit_response` commits status and fields once and returns a
`body_writer`. Write partial spans with `write_some`, or a complete span
with `write`, then call `finish` with optional trailers. Dropping a writer
before finishing fails the remaining body. It cannot replace an already
committed response. P3 abandonment resolves the mandatory trailers future
with an error before releasing the writer; simply dropping that writer
would trap in the component ABI.

`outgoing_exchange::start` takes the scheme, authority, method, path and
fields, starts the host operation and returns a request body writer. Finish
that writer before `receive` waits for response headers. The returned
`incoming_response` provides its status, fields and body. The host owns
connection reuse, DNS and HTTPS trust. Invalid or forbidden fields return
an error; the adapter does not silently switch transports or discard them.
`message_error` retains the pinned interface's host error discriminant.

The operations above suspend inside the current component task. They are not an
Asio completion-token interface. A transfer can use an absolute monotonic
deadline or a cancellation predicate. Cancellation is checked between
chunks and while waiting, at intervals of at most ten milliseconds, except
when the host itself blocks inside an imported operation. The adapter does
not allocate {cpp} operation state. Canonical ABI strings and lists still use
the generated bindings' `cabi_realloc`; caller-owned bodies and fields use
their own allocator.

[#wasi-http-readiness]
=== Nonblocking body and response operations

`<webcpp/wasi/http/poll.hpp>` exposes `read_task`, `write_task` and
`response_task`. Each poll performs one bounded readiness step and returns
false while the host operation remains pending. The tasks own their body
resources and, on P3, stable storage for pending stream and future results.
A pending read or write borrows its payload span until a subsequent poll
completes; the caller must keep that span unchanged and alive. Destroying
a task cancels pending host access before releasing resources or storage.

`read_task::finish` polls body completion and incoming trailers after EOF.
`write_task::finish` polls outgoing trailers after the final content chunk.
`response_task::poll` waits for response headers without blocking on the
network. P2 future tasks retain their readiness subscriptions for the
entire pending interval. These primitives allocate no {cpp} operation
state and can be driven by a component event loop. Beast's explicit WASI
asynchronous adapter builds completion-token operations over them.

[#wasi-cli-streams]
=== Standard CLI streams

`<webcpp/wasi/stdio.hpp>` exposes `stdio_channel` over the pinned wasi-sdk
CLI stream bindings on P2 and P3. Each operation returns a partial byte
count and `ready`, `blocked`, `eof` or `failed`. The object owns the acquired
stream resources; it neither creates sockets nor interprets protocol bytes.
No caller buffer remains borrowed after a partial operation returns.

The direct CLI adapter avoids wasi-sdk 34's stdio descriptors, which reject
`fcntl(F_SETFL)` and always request blocking I/O. Wasmtime 50.0.1 can still
block inside a standard-output host write when its OS pipe fills. Guest
cancellation is then observed after the peer resumes draining. The tests
bound that pause and resume draining concurrently; they do not claim that
the guest can interrupt a blocking host import. Diagnostics belong on
stderr, separately from the protocol on stdout.
2 changes: 1 addition & 1 deletion doc/response.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The handler sends no other header (<<wasi-invariant-7,guarantee 7>>).
A response the handler cannot send as the main wrote it, with a status
outside 100 to 599 or a content type the host refuses, is not sent at all:
the handler answers an internal error, before it has committed anything, and
wasmtime 47 sends that as its own `500 Internal Server Error`, an HTML page
wasmtime 50.0.1 sends that as its own `500 Internal Server Error`, an HTML page
that names it. Without the check, wasmtime would send some of those statuses
as `200 OK`, and the status of `wasi:http`, 16 bits wide, would read 65736 as
200, so a main's bug would reach the client as a success; and a content type
Expand Down
2 changes: 1 addition & 1 deletion doc/testing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ A WASI build needs, besides b2 and Boost 1.92:
| The `wit/deps` directories of the Rust crates `wasip2` 1.0.4 and `wasip3`
0.9.0, which the bindings are generated from.

| wasmtime 47.0.3
| wasmtime 50.0.1
| Runs every test and example, and serves each component.
|===

Expand Down
2 changes: 2 additions & 0 deletions doc/wasi.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ include::wasip3.adoc[]

include::flow.adoc[]

include::messages.adoc[]

include::limits.adoc[]

include::guarantees.adoc[]
Expand Down
2 changes: 1 addition & 1 deletion doc/wasip3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ include::{examples}/by_hand/build.sh[tag=p3]
The test `by_hand` runs them in its lane on wasip3, and wasmtime serves what
they build with the flags above and no other. With exceptions on, an
exception that escapes the main traps the instance: the handler catches
nothing, and wasmtime 47 answers the client with its own
nothing, and wasmtime 50.0.1 answers the client with its own
`500 Internal Server Error` (<<wasi-main-rules>>). Built with
`-fno-exceptions` in place of the exception flags, on the compile and on
the link, the component answers the same; webcpp measured that once, by
Expand Down
2 changes: 1 addition & 1 deletion include/webcpp/wasi/http/entrypoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace webcpp::wasi::http {
the main copies what it keeps beyond the request.
@note The handler catches nothing. On wasip2 and wasip3, where webcpp builds
a program with exceptions, an exception that escapes the main traps the
instance: wasmtime 47 prints the trap and answers the client with its own
instance: wasmtime 50.0.1 prints the trap and answers the client with its own
`500 Internal Server Error`.
@see "Your main", in the guide.
*/
Expand Down
Loading
Loading