Skip to content

Commit

Permalink
test: add http example
Browse files Browse the repository at this point in the history
Reproducer for #27

Signed-off-by: Roman Volosatovs <[email protected]>
  • Loading branch information
rvolosatovs committed Jun 2, 2023
1 parent cdb4b61 commit 1476ea6
Show file tree
Hide file tree
Showing 37 changed files with 2,491 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/http/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
wit_bindgen::generate!({
path: "examples/http/wit",
world: "examples:http/http",
});

fn main() {}
33 changes: 33 additions & 0 deletions examples/http/wit/deps.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[cli]
sha256 = "ce53bedad0aa34bbcde6ffd8f98348e03fa170e191aaf6bb6ca57b4915ade435"
sha512 = "489ed4e04603df4763e75d4d2d056cf363922c4865052348993febfd2c9bd10ab864fb4b72090df58dcb60d5676148a7a1e7de3a8513073afd37b4d9027ca7e7"

[clocks]
sha256 = "1ed7e35b3f9738663854f0dd92a95bfadc410ea07170501f5c2fec0cc24e3d57"
sha512 = "ef1e23704a8a8436fd3718593d4c4d8b6d1c64dad3595b7496c0888ca14b725046f2900109800faca1bc8c14f237cdcaca791dba8284e1ad50105ab2d036825b"

[filesystem]
sha256 = "a19dbd57208ef649980bb4088b96606fe3549e580574dc88dafed6f8a8537b01"
sha512 = "49a798126feeb1a714162a20d282e554c70d36cbfa827dfb54685577b13d584fa15e02fd653fbb940a4fa52cece6c0ca4d7cd85f27c041a5cc99a98392d03e50"

[http]
url = "https://github.com/WebAssembly/wasi-http/archive/main.tar.gz"
sha256 = "3d41ce13364177bdf7eea92d78d9ab302ccd5d9462cfdf074677d50244c565b1"
sha512 = "1e37c5ae0b93dfa11f722e23cf9b5589976ba1e9a6e63feed930c2ebb15289d8ca7e8fcc5213aa39e0a7e2d852ecb6885dde88f21a99f70aced5c17ef381ff72"
deps = ["cli", "clocks", "filesystem", "io", "poll", "random", "sockets"]

[io]
sha256 = "eeb4701c2becafa40a7ee3bf0d2c94e2170e15806b25abdcd1de1ed94f2c1036"
sha512 = "89be853b2acae211570cd6ad0ec9d8132881dafbdea83ac7b4cad600f0627003c61f310427379bf47ecf862724367bd5d6e976db70069f6f90a3c2d9c20dbfb7"

[poll]
sha256 = "9f8bb4d9994e9b0684859bb1e8bee2a8b873e04d40695f260446760fc44d0c58"
sha512 = "aa8da395ba6e189ec113296996da5abf28bdc4460e4eb2aacc786698ced892e08f7054fb590fc8809c05554d5c83a11494d4ab68c755746f57d151e212415cfb"

[random]
sha256 = "30731531ec3453813d08765b428f34aec34ac343cbeafd9885e4e348d187ae04"
sha512 = "6656089f9297ee56cf58c2f95c466e3a22c371925404e6eb9cb5adcb37c1b92f27aaf8c2f9e690ac53ef12f90bd31ac64a84d5f5e06d3f06e24997478275327f"

[sockets]
sha256 = "30c07587eda24676185f175323d5195817b5678815a3f6b64b8152a5b7532493"
sha512 = "8965e112c323e4535786361d864d3b5020791ce7e48da20a6a6b9a1fbec1f78bc10e0830c640f704bd8132fada56cd8a19b48e11e60ec6d9191c08e00550c91c"
1 change: 1 addition & 0 deletions examples/http/wit/deps.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http = "https://github.com/WebAssembly/wasi-http/archive/main.tar.gz"
27 changes: 27 additions & 0 deletions examples/http/wit/deps/cli/command.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package wasi:cli

world command {
import wasi:clocks/wall-clock
import wasi:clocks/monotonic-clock
import wasi:clocks/timezone
import wasi:filesystem/types
import wasi:sockets/instance-network
import wasi:sockets/ip-name-lookup
import wasi:sockets/network
import wasi:sockets/tcp-create-socket
import wasi:sockets/tcp
import wasi:sockets/udp-create-socket
import wasi:sockets/udp
import wasi:random/random
import wasi:random/insecure
import wasi:random/insecure-seed
import wasi:poll/poll
import wasi:io/streams
import environment
import preopens
import exit
import stdin
import stdout
import stderr
export run
}
14 changes: 14 additions & 0 deletions examples/http/wit/deps/cli/environment.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
interface environment {
/// Get the POSIX-style environment variables.
///
/// Each environment variable is provided as a pair of string variable names
/// and string value.
///
/// Morally, these are a value import, but until value imports are available
/// in the component model, this import function should return the same
/// values each time it is called.
get-environment: func() -> list<tuple<string, string>>

/// Get the POSIX-style arguments to the program.
get-arguments: func() -> list<string>
}
4 changes: 4 additions & 0 deletions examples/http/wit/deps/cli/exit.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface exit {
/// Exit the curerent instance and any linked instances.
exit: func(status: result)
}
11 changes: 11 additions & 0 deletions examples/http/wit/deps/cli/preopens.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
interface preopens {
use wasi:filesystem/types.{descriptor}
use wasi:io/streams.{input-stream, output-stream}

/// Return the set of of preopened directories, and their path.
get-directories: func() -> list<tuple<descriptor, string>>

/// Return a path that programs should use as their initial current working
/// directory, interpreting `.` as shorthand for this.
initial-cwd: func() -> option<string>
}
4 changes: 4 additions & 0 deletions examples/http/wit/deps/cli/run.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface run {
/// Run the program.
run: func() -> result
}
17 changes: 17 additions & 0 deletions examples/http/wit/deps/cli/stdio.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
interface stdin {
use wasi:io/streams.{input-stream}

get-stdin: func() -> input-stream
}

interface stdout {
use wasi:io/streams.{output-stream}

get-stdout: func() -> output-stream
}

interface stderr {
use wasi:io/streams.{output-stream}

get-stderr: func() -> output-stream
}
59 changes: 59 additions & 0 deletions examples/http/wit/deps/cli/terminal.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
interface terminal-input {
/// The input side of a terminal.
///
/// This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
type terminal-input = u32

// In the future, this may include functions for disabling echoing,
// disabling input buffering so that keyboard events are sent through
// immediately, querying supported features, and so on.

/// Dispose of the specified terminal-input after which it may no longer
/// be used.
drop-terminal-input: func(this: terminal-input)
}

interface terminal-output {
/// The output side of a terminal.
///
/// This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
type terminal-output = u32

// In the future, this may include functions for querying the terminal
// size, being notified of terminal size changes, querying supported
// features, and so on.

/// Dispose of the specified terminal-output, after which it may no longer
/// be used.
drop-terminal-output: func(this: terminal-output)
}

/// An interface providing an optional `terminal-input` for stdin as a
/// link-time authority.
interface terminal-stdin {
use terminal-input.{terminal-input}

/// If stdin is connected to a terminal, return a `terminal-input` handle
/// allowing further interaction with it.
get-terminal-stdin: func() -> option<terminal-input>
}

/// An interface providing an optional `terminal-output` for stdout as a
/// link-time authority.
interface terminal-stdout {
use terminal-output.{terminal-output}

/// If stdout is connected to a terminal, return a `terminal-output` handle
/// allowing further interaction with it.
get-terminal-stdout: func() -> option<terminal-output>
}

/// An interface providing an optional `terminal-output` for stderr as a
/// link-time authority.
interface terminal-stderr {
use terminal-output.{terminal-output}

/// If stderr is connected to a terminal, return a `terminal-output` handle
/// allowing further interaction with it.
get-terminal-stderr: func() -> option<terminal-output>
}
32 changes: 32 additions & 0 deletions examples/http/wit/deps/clocks/monotonic-clock.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// WASI Monotonic Clock is a clock API intended to let users measure elapsed
/// time.
///
/// It is intended to be portable at least between Unix-family platforms and
/// Windows.
///
/// A monotonic clock is a clock which has an unspecified initial value, and
/// successive reads of the clock will produce non-decreasing values.
///
/// It is intended for measuring elapsed time.
interface monotonic-clock {
use wasi:poll/poll.{pollable}

/// A timestamp in nanoseconds.
type instant = u64

/// Read the current value of the clock.
///
/// The clock is monotonic, therefore calling this function repeatedly will
/// produce a sequence of non-decreasing values.
now: func() -> instant

/// Query the resolution of the clock.
resolution: func() -> instant

/// Create a `pollable` which will resolve once the specified time has been
/// reached.
subscribe: func(
when: instant,
absolute: bool
) -> pollable
}
61 changes: 61 additions & 0 deletions examples/http/wit/deps/clocks/timezone.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
interface timezone {
use wall-clock.{datetime}

/// A timezone.
///
/// In timezones that recognize daylight saving time, also known as daylight
/// time and summer time, the information returned from the functions varies
/// over time to reflect these adjustments.
///
/// This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
type timezone = u32

/// Return information needed to display the given `datetime`. This includes
/// the UTC offset, the time zone name, and a flag indicating whether
/// daylight saving time is active.
///
/// If the timezone cannot be determined for the given `datetime`, return a
/// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
/// saving time.
display: func(this: timezone, when: datetime) -> timezone-display

/// The same as `display`, but only return the UTC offset.
utc-offset: func(this: timezone, when: datetime) -> s32

/// Dispose of the specified input-stream, after which it may no longer
/// be used.
drop-timezone: func(this: timezone)

/// Information useful for displaying the timezone of a specific `datetime`.
///
/// This information may vary within a single `timezone` to reflect daylight
/// saving time adjustments.
record timezone-display {
/// The number of seconds difference between UTC time and the local
/// time of the timezone.
///
/// The returned value will always be less than 86400 which is the
/// number of seconds in a day (24*60*60).
///
/// In implementations that do not expose an actual time zone, this
/// should return 0.
utc-offset: s32,

/// The abbreviated name of the timezone to display to a user. The name
/// `UTC` indicates Coordinated Universal Time. Otherwise, this should
/// reference local standards for the name of the time zone.
///
/// In implementations that do not expose an actual time zone, this
/// should be the string `UTC`.
///
/// In time zones that do not have an applicable name, a formatted
/// representation of the UTC offset may be returned, such as `-04:00`.
name: string,

/// Whether daylight saving time is active.
///
/// In implementations that do not expose an actual time zone, this
/// should return false.
in-daylight-saving-time: bool,
}
}
41 changes: 41 additions & 0 deletions examples/http/wit/deps/clocks/wall-clock.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/// WASI Wall Clock is a clock API intended to let users query the current
/// time. The name "wall" makes an analogy to a "clock on the wall", which
/// is not necessarily monotonic as it may be reset.
///
/// It is intended to be portable at least between Unix-family platforms and
/// Windows.
///
/// A wall clock is a clock which measures the date and time according to
/// some external reference.
///
/// External references may be reset, so this clock is not necessarily
/// monotonic, making it unsuitable for measuring elapsed time.
///
/// It is intended for reporting the current date and time for humans.
interface wall-clock {
/// A time and date in seconds plus nanoseconds.
record datetime {
seconds: u64,
nanoseconds: u32,
}

/// Read the current value of the clock.
///
/// This clock is not monotonic, therefore calling this function repeatedly
/// will not necessarily produce a sequence of non-decreasing values.
///
/// The returned timestamps represent the number of seconds since
/// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch],
/// also known as [Unix Time].
///
/// The nanoseconds field of the output is always less than 1000000000.
///
/// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
/// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
now: func() -> datetime

/// Query the resolution of the clock.
///
/// The nanoseconds field of the output is always less than 1000000000.
resolution: func() -> datetime
}
7 changes: 7 additions & 0 deletions examples/http/wit/deps/clocks/world.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package wasi:clocks

world example-world {
import monotonic-clock
import wall-clock
import timezone
}
Loading

0 comments on commit 1476ea6

Please sign in to comment.