Skip to content

Commit 1476ea6

Browse files
committed
test: add http example
Reproducer for #27 Signed-off-by: Roman Volosatovs <[email protected]>
1 parent cdb4b61 commit 1476ea6

37 files changed

+2491
-0
lines changed

examples/http/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
wit_bindgen::generate!({
2+
path: "examples/http/wit",
3+
world: "examples:http/http",
4+
});
5+
6+
fn main() {}

examples/http/wit/deps.lock

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[cli]
2+
sha256 = "ce53bedad0aa34bbcde6ffd8f98348e03fa170e191aaf6bb6ca57b4915ade435"
3+
sha512 = "489ed4e04603df4763e75d4d2d056cf363922c4865052348993febfd2c9bd10ab864fb4b72090df58dcb60d5676148a7a1e7de3a8513073afd37b4d9027ca7e7"
4+
5+
[clocks]
6+
sha256 = "1ed7e35b3f9738663854f0dd92a95bfadc410ea07170501f5c2fec0cc24e3d57"
7+
sha512 = "ef1e23704a8a8436fd3718593d4c4d8b6d1c64dad3595b7496c0888ca14b725046f2900109800faca1bc8c14f237cdcaca791dba8284e1ad50105ab2d036825b"
8+
9+
[filesystem]
10+
sha256 = "a19dbd57208ef649980bb4088b96606fe3549e580574dc88dafed6f8a8537b01"
11+
sha512 = "49a798126feeb1a714162a20d282e554c70d36cbfa827dfb54685577b13d584fa15e02fd653fbb940a4fa52cece6c0ca4d7cd85f27c041a5cc99a98392d03e50"
12+
13+
[http]
14+
url = "https://github.com/WebAssembly/wasi-http/archive/main.tar.gz"
15+
sha256 = "3d41ce13364177bdf7eea92d78d9ab302ccd5d9462cfdf074677d50244c565b1"
16+
sha512 = "1e37c5ae0b93dfa11f722e23cf9b5589976ba1e9a6e63feed930c2ebb15289d8ca7e8fcc5213aa39e0a7e2d852ecb6885dde88f21a99f70aced5c17ef381ff72"
17+
deps = ["cli", "clocks", "filesystem", "io", "poll", "random", "sockets"]
18+
19+
[io]
20+
sha256 = "eeb4701c2becafa40a7ee3bf0d2c94e2170e15806b25abdcd1de1ed94f2c1036"
21+
sha512 = "89be853b2acae211570cd6ad0ec9d8132881dafbdea83ac7b4cad600f0627003c61f310427379bf47ecf862724367bd5d6e976db70069f6f90a3c2d9c20dbfb7"
22+
23+
[poll]
24+
sha256 = "9f8bb4d9994e9b0684859bb1e8bee2a8b873e04d40695f260446760fc44d0c58"
25+
sha512 = "aa8da395ba6e189ec113296996da5abf28bdc4460e4eb2aacc786698ced892e08f7054fb590fc8809c05554d5c83a11494d4ab68c755746f57d151e212415cfb"
26+
27+
[random]
28+
sha256 = "30731531ec3453813d08765b428f34aec34ac343cbeafd9885e4e348d187ae04"
29+
sha512 = "6656089f9297ee56cf58c2f95c466e3a22c371925404e6eb9cb5adcb37c1b92f27aaf8c2f9e690ac53ef12f90bd31ac64a84d5f5e06d3f06e24997478275327f"
30+
31+
[sockets]
32+
sha256 = "30c07587eda24676185f175323d5195817b5678815a3f6b64b8152a5b7532493"
33+
sha512 = "8965e112c323e4535786361d864d3b5020791ce7e48da20a6a6b9a1fbec1f78bc10e0830c640f704bd8132fada56cd8a19b48e11e60ec6d9191c08e00550c91c"

examples/http/wit/deps.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http = "https://github.com/WebAssembly/wasi-http/archive/main.tar.gz"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package wasi:cli
2+
3+
world command {
4+
import wasi:clocks/wall-clock
5+
import wasi:clocks/monotonic-clock
6+
import wasi:clocks/timezone
7+
import wasi:filesystem/types
8+
import wasi:sockets/instance-network
9+
import wasi:sockets/ip-name-lookup
10+
import wasi:sockets/network
11+
import wasi:sockets/tcp-create-socket
12+
import wasi:sockets/tcp
13+
import wasi:sockets/udp-create-socket
14+
import wasi:sockets/udp
15+
import wasi:random/random
16+
import wasi:random/insecure
17+
import wasi:random/insecure-seed
18+
import wasi:poll/poll
19+
import wasi:io/streams
20+
import environment
21+
import preopens
22+
import exit
23+
import stdin
24+
import stdout
25+
import stderr
26+
export run
27+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
interface environment {
2+
/// Get the POSIX-style environment variables.
3+
///
4+
/// Each environment variable is provided as a pair of string variable names
5+
/// and string value.
6+
///
7+
/// Morally, these are a value import, but until value imports are available
8+
/// in the component model, this import function should return the same
9+
/// values each time it is called.
10+
get-environment: func() -> list<tuple<string, string>>
11+
12+
/// Get the POSIX-style arguments to the program.
13+
get-arguments: func() -> list<string>
14+
}

examples/http/wit/deps/cli/exit.wit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface exit {
2+
/// Exit the curerent instance and any linked instances.
3+
exit: func(status: result)
4+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
interface preopens {
2+
use wasi:filesystem/types.{descriptor}
3+
use wasi:io/streams.{input-stream, output-stream}
4+
5+
/// Return the set of of preopened directories, and their path.
6+
get-directories: func() -> list<tuple<descriptor, string>>
7+
8+
/// Return a path that programs should use as their initial current working
9+
/// directory, interpreting `.` as shorthand for this.
10+
initial-cwd: func() -> option<string>
11+
}

examples/http/wit/deps/cli/run.wit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface run {
2+
/// Run the program.
3+
run: func() -> result
4+
}

examples/http/wit/deps/cli/stdio.wit

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
interface stdin {
2+
use wasi:io/streams.{input-stream}
3+
4+
get-stdin: func() -> input-stream
5+
}
6+
7+
interface stdout {
8+
use wasi:io/streams.{output-stream}
9+
10+
get-stdout: func() -> output-stream
11+
}
12+
13+
interface stderr {
14+
use wasi:io/streams.{output-stream}
15+
16+
get-stderr: func() -> output-stream
17+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
interface terminal-input {
2+
/// The input side of a terminal.
3+
///
4+
/// This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
5+
type terminal-input = u32
6+
7+
// In the future, this may include functions for disabling echoing,
8+
// disabling input buffering so that keyboard events are sent through
9+
// immediately, querying supported features, and so on.
10+
11+
/// Dispose of the specified terminal-input after which it may no longer
12+
/// be used.
13+
drop-terminal-input: func(this: terminal-input)
14+
}
15+
16+
interface terminal-output {
17+
/// The output side of a terminal.
18+
///
19+
/// This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
20+
type terminal-output = u32
21+
22+
// In the future, this may include functions for querying the terminal
23+
// size, being notified of terminal size changes, querying supported
24+
// features, and so on.
25+
26+
/// Dispose of the specified terminal-output, after which it may no longer
27+
/// be used.
28+
drop-terminal-output: func(this: terminal-output)
29+
}
30+
31+
/// An interface providing an optional `terminal-input` for stdin as a
32+
/// link-time authority.
33+
interface terminal-stdin {
34+
use terminal-input.{terminal-input}
35+
36+
/// If stdin is connected to a terminal, return a `terminal-input` handle
37+
/// allowing further interaction with it.
38+
get-terminal-stdin: func() -> option<terminal-input>
39+
}
40+
41+
/// An interface providing an optional `terminal-output` for stdout as a
42+
/// link-time authority.
43+
interface terminal-stdout {
44+
use terminal-output.{terminal-output}
45+
46+
/// If stdout is connected to a terminal, return a `terminal-output` handle
47+
/// allowing further interaction with it.
48+
get-terminal-stdout: func() -> option<terminal-output>
49+
}
50+
51+
/// An interface providing an optional `terminal-output` for stderr as a
52+
/// link-time authority.
53+
interface terminal-stderr {
54+
use terminal-output.{terminal-output}
55+
56+
/// If stderr is connected to a terminal, return a `terminal-output` handle
57+
/// allowing further interaction with it.
58+
get-terminal-stderr: func() -> option<terminal-output>
59+
}

0 commit comments

Comments
 (0)