├── .devcontainer ├── Dockerfile └── devcontainer.json ├── .gitignore ├── .vscode └── tasks.json ├── LICENSE ├── README.md ├── examples └── component_main │ ├── .gitignore │ ├── Makefile │ ├── component_main.go │ ├── go.mod │ └── go.sum ├── http ├── .gitignore ├── Makefile ├── README.md ├── client.wit ├── go.mod ├── go.sum └── main.go ├── lib ├── go.mod ├── go.sum ├── http │ ├── client │ │ ├── transport.go │ │ └── transport_test.go │ └── server │ │ ├── handler │ │ └── handler.go │ │ └── server.go ├── wasi │ ├── .gitignore │ ├── Makefile │ ├── cli │ │ ├── run │ │ │ ├── empty.s │ │ │ ├── run.exports.go │ │ │ └── run.wit.go │ │ ├── stderr │ │ │ ├── empty.s │ │ │ └── stderr.wit.go │ │ ├── stdin │ │ │ ├── empty.s │ │ │ └── stdin.wit.go │ │ └── stdout │ │ │ ├── empty.s │ │ │ └── stdout.wit.go │ ├── clocks │ │ ├── monotonic-clock │ │ │ ├── empty.s │ │ │ └── monotonic-clock.wit.go │ │ └── wall-clock │ │ │ ├── empty.s │ │ │ └── wall-clock.wit.go │ ├── http │ │ ├── incoming-handler │ │ │ ├── empty.s │ │ │ ├── incoming-handler.exports.go │ │ │ └── incoming-handler.wit.go │ │ ├── outgoing-handler │ │ │ ├── abi.go │ │ │ ├── empty.s │ │ │ └── outgoing-handler.wit.go │ │ ├── types │ │ │ ├── abi.go │ │ │ ├── empty.s │ │ │ └── types.wit.go │ │ └── wasi │ │ │ └── wasi.wit.go │ ├── io │ │ ├── error │ │ │ ├── empty.s │ │ │ └── error.wit.go │ │ ├── poll │ │ │ ├── empty.s │ │ │ └── poll.wit.go │ │ └── streams │ │ │ ├── abi.go │ │ │ ├── empty.s │ │ │ └── streams.wit.go │ ├── random │ │ └── random │ │ │ ├── empty.s │ │ │ └── random.wit.go │ └── wasi.wit ├── wasi_snapshot_preview1.reactor.0_2_0.wasm └── wasi_snapshot_preview1.reactor.2023_11_10.wasm ├── main.go └── webserver ├── wagi ├── go.mod ├── lighttpd.conf └── wagi.go └── wasi-http ├── .gitignore ├── Makefile ├── go.mod ├── go.sum └── main.go /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | 2 | FROM --platform=$BUILDPLATFORM ubuntu:jammy 3 | 4 | ARG TARGETPLATFORM 5 | ARG BUILDPLATFORM 6 | 7 | ENV TINY_GO_VERSION=0.33.0 8 | ENV GOLANG_VERSION=1.23.0 9 | 10 | RUN apt-get update && apt-get install -yy -q curl 11 | 12 | RUN archi=$(echo $TARGETPLATFORM | cut -d / -f2) && \ 13 | curl https://github.com/tinygo-org/tinygo/releases/download/v${TINY_GO_VERSION}/tinygo_${TINY_GO_VERSION}_$archi.deb -L --output tinygo_${TINY_GO_VERSION}_$archi.deb && \ 14 | dpkg -i tinygo_${TINY_GO_VERSION}_$archi.deb && \ 15 | rm tinygo_${TINY_GO_VERSION}_$archi.deb && \ 16 | curl --output go${GOLANG_VERSION}.linux-$archi.tar.gz https://go.dev/dl/go${GOLANG_VERSION}.linux-$archi.tar.gz -L && \ 17 | tar -C /usr/local -xzf go${GOLANG_VERSION}.linux-$archi.tar.gz && \ 18 | rm go${GOLANG_VERSION}.linux-$archi.tar.gz 19 | 20 | RUN apt install -y -q make 21 | 22 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Go WASM", 3 | "build": { 4 | "dockerfile": "Dockerfile", 5 | "context": ".." 6 | }, 7 | "features": { 8 | "devwasm.azurecr.io/dev-wasm/dev-wasm-feature/wasmtime-wasi:0.0.16": { 9 | "version": "24", 10 | "wasmtime_version": "v22.0.0", 11 | "wit_version": "0.30.0", 12 | "wasm_tools_version": "1.216.0" 13 | }, 14 | "ghcr.io/devcontainers/features/common-utils": {} 15 | }, 16 | "remoteEnv": { 17 | "PATH": "${containerEnv:PATH}:/usr/local/lib/wasi-sdk-24.0/bin:/usr/local/lib:/usr/local/go/bin", 18 | "GOROOT": "/usr/local/go" 19 | }, 20 | "customizations": { 21 | "vscode": { 22 | "extensions": [ "ms-vscode.cpptools-extension-pack", "golang.go" ] 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/*.wasm 2 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "Build Go", 6 | "type": "shell", 7 | "command": "tinygo build -wasm-abi=generic -target=wasi -o main.wasm main.go", 8 | "group": "build", 9 | "presentation": { 10 | "reveal": "always", 11 | "panel": "new" 12 | } 13 | }, 14 | ] 15 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 dev-wasm 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Devcontainer WASM-Go 2 | Simple devcontainer for Go development 3 | 4 | # Usage 5 | 6 | ## Github Codespaces 7 | Just click the button: 8 | 9 | [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=575629782) 10 | 11 | 12 | 13 | ## Visual Studio Code 14 | Note this assumes that you have the VS code support for remote containers and `docker` installed 15 | on your machine. 16 | 17 | ```sh 18 | git clone https://github.com/dev-wasm/dev-wasm-go 19 | cd dev-wasm-go 20 | code ./ 21 | ``` 22 | 23 | Visual studio should prompt you to see if you want to relaunch the workspace in a container, you do. 24 | 25 | # Building and Running 26 | 27 | ## Simple example 28 | ```sh 29 | # Build with TinyGo 30 | tinygo build -target=wasi -o main.wasm main.go 31 | # Or Build with Golang native 32 | GOOS=wasip1 GOARCH=wasm go build -o main.wasm main.go 33 | 34 | # Run it 35 | wasmtime --dir .::/ main.wasm 36 | ``` 37 | 38 | 39 | 40 | ## WASM Web serving with WASI-HTTP 41 | There is an example of web serving via the [WASI-HTTP](https://github.com/WebAssembly/wasi-http) API 42 | in `webserver/wasi-http`. 43 | 44 | To build: 45 | ```sh 46 | # Install the wit interface files, this only needs to be done once. 47 | cd lib/wasi 48 | make wasi-http 49 | 50 | # Return to root 51 | cd ../../ 52 | 53 | # Build the wasm component 54 | cd webserver/wasi-http 55 | make clean 56 | make default 57 | make run 58 | ``` 59 | 60 | Once it is running you can connect to it via http://localhost:8080 61 | 62 | ## WASM CGI web serving with lighttpd 63 | There is an example of web serving via WebAssembly + CGI (WAGI) in 64 | the `webserver/wagi` directory. It uses the lighttpd web server and `mod_cgi`. 65 | See the `webserver/lighttpd.conf` file for more details. 66 | 67 | ```sh 68 | tinygo build -target=wasi -o wagi.wasm webserver/wagi.go 69 | lighttpd -D -f webserver/lighttpd.conf 70 | ``` 71 | 72 | Once the server is running, VS Code or Codespaces should prompt you to connect to the open port. 73 | 74 | ## HTTP Client Example 75 | There is a more complicated example in the [`http` directory](./http/) which shows an example 76 | of making an HTTP client call using the experimental wasi-http support in `wasmtime`. 77 | 78 | -------------------------------------------------------------------------------- /examples/component_main/.gitignore: -------------------------------------------------------------------------------- 1 | wasi-cli-0.2.0 2 | -------------------------------------------------------------------------------- /examples/component_main/Makefile: -------------------------------------------------------------------------------- 1 | .phony: clean run 2 | 3 | default: main.component.wasm 4 | 5 | wasi-cli-0.2.0: ; wget https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v0.2.0.tar.gz ; tar -xzf v0.2.0.tar.gz ; rm v0.2.0.tar.gz 6 | 7 | main.wasm: component_main.go ; tinygo build -target=wasi -o main.wasm -tags purego 8 | 9 | main.embed.wasm: main.wasm wasi-cli-0.2.0; wasm-tools component embed wasi-cli-0.2.0/wit/ -w command main.wasm -o main.embed.wasm 10 | 11 | main.component.wasm: main.embed.wasm ; wasm-tools component new main.embed.wasm -o main.component.wasm --adapt ../../lib/wasi_snapshot_preview1.reactor.0_2_0.wasm 12 | 13 | clean: ; rm -rf main*.wasm wasi-cli-0.2.0 v0.2.0.tar.gz 14 | 15 | run: main.component.wasm ; WASMTIME_BACKTRACE_DETAILS=1 wasmtime -S http --wasm component-model main.component.wasm -------------------------------------------------------------------------------- /examples/component_main/component_main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | "time" 7 | 8 | "github.com/dev-wasm/dev-wasm-go/lib/wasi/cli/run" 9 | "github.com/ydnar/wasm-tools-go/cm" 10 | ) 11 | 12 | func Run() cm.BoolResult { 13 | main() 14 | return cm.BoolResult(false) 15 | } 16 | 17 | func init() { 18 | run.Exports.Run = Run 19 | } 20 | 21 | func main() { 22 | fmt.Println("Hello world!") 23 | fmt.Printf("Time is: %v\n", time.Now()) 24 | fmt.Printf("Random number is %v\n", rand.Int()) 25 | } 26 | -------------------------------------------------------------------------------- /examples/component_main/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/dev-wasm/dev-wasm-go/examples/component_main 2 | 3 | require ( 4 | github.com/dev-wasm/dev-wasm-go v0.0.0-20240903232551-3526e9637f2b // indirect 5 | github.com/dev-wasm/dev-wasm-go/lib v0.0.0-20240903233842-b25e2e499927 // indirect 6 | github.com/ydnar/wasm-tools-go v0.1.5 // indirect 7 | ) 8 | 9 | replace github.com/dev-wasm/dev-wasm-go/lib/ v0.0.0 => ../../lib/ 10 | 11 | go 1.22.0 12 | 13 | toolchain go1.23.0 14 | -------------------------------------------------------------------------------- /examples/component_main/go.sum: -------------------------------------------------------------------------------- 1 | github.com/dev-wasm/dev-wasm-go v0.0.0-20240903232551-3526e9637f2b h1:ePgn3zA/f73orXx0LO/UPL8gausq6w3CGdEfFuq2mFM= 2 | github.com/dev-wasm/dev-wasm-go v0.0.0-20240903232551-3526e9637f2b/go.mod h1:0B1yjENHxtWKjCfmluGgtezq/bfen86rNhVTZBiLo6E= 3 | github.com/dev-wasm/dev-wasm-go/lib v0.0.0-20240828183202-21561ad166e4 h1:WVwIL8iF8suKXHzdVDefkFo1mjYvMOoA5SnLrjrtUOY= 4 | github.com/dev-wasm/dev-wasm-go/lib v0.0.0-20240828183202-21561ad166e4/go.mod h1:eyHGUpflr/37EgTuiJg+m+qz9zVeq6Ffk1ltvWMb8qY= 5 | github.com/dev-wasm/dev-wasm-go/lib v0.0.0-20240903233842-b25e2e499927 h1:6d2BT8T/D7NZ/8sIGFn03t5fuvYlRaVQuxb0IyVzPo8= 6 | github.com/dev-wasm/dev-wasm-go/lib v0.0.0-20240903233842-b25e2e499927/go.mod h1:xi8sLzp98HaAHL9V87SHzaHnO67qi6fyUVH2JRUA4Ds= 7 | github.com/ydnar/wasm-tools-go v0.1.5 h1:ah2WT4gH0IrmN29ZSsjgNC9SPsdXZ+KN+o9uTZqNVSI= 8 | github.com/ydnar/wasm-tools-go v0.1.5/go.mod h1:L3sDi5rbAMJNmMO5cpDRzYYhB0r9xIU0xgpKjwU0Adg= 9 | -------------------------------------------------------------------------------- /http/.gitignore: -------------------------------------------------------------------------------- 1 | wasi-http* 2 | -------------------------------------------------------------------------------- /http/Makefile: -------------------------------------------------------------------------------- 1 | .phony: clean run 2 | 3 | default: main.component.wasm 4 | 5 | wasi-http-0.2.0: 6 | wget https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.0.tar.gz 7 | tar -xzf v0.2.0.tar.gz ; rm v0.2.0.tar.gz 8 | cp client.wit wasi-http-0.2.0/wit/client.wit 9 | 10 | main.wasm: ; tinygo build -target=wasip1 -o main.wasm -tags purego main.go 11 | 12 | main.embed.wasm: main.wasm wasi-http-0.2.0; wasm-tools component embed wasi-http-0.2.0/wit/ -w client main.wasm -o main.embed.wasm 13 | 14 | main.component.wasm: main.embed.wasm ; wasm-tools component new main.embed.wasm -o main.component.wasm --adapt ../lib/wasi_snapshot_preview1.reactor.0_2_0.wasm 15 | 16 | clean: ; rm -rf main*.wasm wasi-http-0.2.0 17 | 18 | run: main.component.wasm ; WASMTIME_BACKTRACE_DETAILS=1 wasmtime -S http --wasm component-model main.component.wasm -------------------------------------------------------------------------------- /http/README.md: -------------------------------------------------------------------------------- 1 | # Experimental HTTP Client Example 2 | *NB*: this example uses an experimental `wasmtime-http` that incorporates a highly 3 | experimental HTTP client library that is not yet part of the WASI specification. 4 | Use at your own risk, things are likely to change drastically in the future. 5 | 6 | ## Building 7 | ```sh 8 | tinygo build -target=wasi -o main.wasm -tags purego 9 | ``` 10 | 11 | ## Running 12 | ```sh 13 | wasmtime --wasi-modules=experimental-wasi-http main.wasm 14 | ``` 15 | 16 | 17 | -------------------------------------------------------------------------------- /http/client.wit: -------------------------------------------------------------------------------- 1 | package wasi:http@0.2.0; 2 | 3 | /// The `wasi:http/client` world captures making outgoing HTTP requests. 4 | world client { 5 | /// HTTP proxies have access to time and randomness. 6 | include wasi:clocks/imports@0.2.0; 7 | import wasi:random/random@0.2.0; 8 | 9 | /// Proxies have standard output and error streams which are expected to 10 | /// terminate in a developer-facing console provided by the host. 11 | import wasi:cli/stdout@0.2.0; 12 | import wasi:cli/stderr@0.2.0; 13 | 14 | /// TODO: this is a temporary workaround until component tooling is able to 15 | /// gracefully handle the absence of stdin. Hosts must return an eof stream 16 | /// for this import, which is what wasi-libc + tooling will do automatically 17 | /// when this import is properly removed. 18 | import wasi:cli/stdin@0.2.0; 19 | 20 | /// This is the default handler to use when user code simply wants to make an 21 | /// HTTP request (e.g., via `fetch()`). 22 | import outgoing-handler; 23 | 24 | export wasi:cli/run@0.2.0; 25 | } 26 | -------------------------------------------------------------------------------- /http/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/dev-wasm/dev-wasm-go/http 2 | 3 | go 1.22.0 4 | 5 | toolchain go1.22.5 6 | 7 | require ( 8 | github.com/dev-wasm/dev-wasm-go/lib v0.0.0 // indirect 9 | github.com/ydnar/wasm-tools-go v0.1.5 // indirect 10 | ) 11 | 12 | replace github.com/dev-wasm/dev-wasm-go/lib v0.0.0 => ../lib 13 | -------------------------------------------------------------------------------- /http/go.sum: -------------------------------------------------------------------------------- 1 | github.com/ydnar/wasm-tools-go v0.1.5 h1:ah2WT4gH0IrmN29ZSsjgNC9SPsdXZ+KN+o9uTZqNVSI= 2 | github.com/ydnar/wasm-tools-go v0.1.5/go.mod h1:L3sDi5rbAMJNmMO5cpDRzYYhB0r9xIU0xgpKjwU0Adg= 3 | -------------------------------------------------------------------------------- /http/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "net/http" 7 | "unsafe" 8 | 9 | wasiclient "github.com/dev-wasm/dev-wasm-go/lib/http/client" 10 | "github.com/dev-wasm/dev-wasm-go/lib/wasi/cli/run" 11 | "github.com/ydnar/wasm-tools-go/cm" 12 | ) 13 | 14 | // This is required for building the module for some reason 15 | // I don't think it should be. I'm probably doing something 16 | // wrong. 17 | // 18 | // fwiw, I think this is likely buggy and either leaks memory 19 | // or has race conditions. 20 | // 21 | //go:wasmexport cabi_realloc 22 | //export cabi_realloc 23 | func wasmexport_cabi_realloc(ptr, oldSize, align, newSize uint32) uint32 { 24 | if newSize == 0 { 25 | return align 26 | } 27 | arr := make([]uint8, newSize) 28 | newPtr := unsafe.Pointer(unsafe.SliceData(arr)) 29 | return uint32(uintptr(newPtr)) 30 | } 31 | 32 | func printResponse(r *http.Response) { 33 | fmt.Printf("Status: %d\n", r.StatusCode) 34 | for k, v := range r.Header { 35 | fmt.Printf("%s: %s\n", k, v[0]) 36 | } 37 | body, err := ioutil.ReadAll(r.Body) 38 | if err != nil { 39 | panic(err.Error()) 40 | } 41 | fmt.Printf("Body: \n%s\n", body) 42 | } 43 | 44 | func Run() cm.BoolResult { 45 | main() 46 | return cm.BoolResult(false) 47 | } 48 | 49 | func init() { 50 | run.Exports.Run = Run 51 | } 52 | 53 | func main() { 54 | client := &http.Client{ 55 | Transport: wasiclient.WasiRoundTripper{}, 56 | } 57 | req, err := http.NewRequest("GET", "https://postman-echo.com/get", nil) 58 | if err != nil { 59 | panic(err.Error()) 60 | } 61 | if req == nil { 62 | panic("Nil request!") 63 | } 64 | res, err := client.Do(req) 65 | if err != nil { 66 | panic(err.Error()) 67 | } 68 | defer res.Body.Close() 69 | printResponse(res) 70 | 71 | res, err = client.Post("https://postman-echo.com/post", "application/json", wasiclient.BodyReaderCloser([]byte("{\"foo\": \"bar\"}"))) 72 | if err != nil { 73 | panic(err.Error()) 74 | } 75 | defer res.Body.Close() 76 | printResponse(res) 77 | 78 | res, err = wasiclient.Put(client, "http://postman-echo.com/put", "application/json", wasiclient.BodyReaderCloser([]byte("{\"baz\": \"blah\"}"))) 79 | if err != nil { 80 | panic(err.Error()) 81 | } 82 | defer res.Body.Close() 83 | printResponse(res) 84 | } 85 | -------------------------------------------------------------------------------- /lib/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/dev-wasm/dev-wasm-go/lib 2 | 3 | go 1.22.0 4 | 5 | require github.com/ydnar/wasm-tools-go v0.1.5 6 | -------------------------------------------------------------------------------- /lib/go.sum: -------------------------------------------------------------------------------- 1 | github.com/ydnar/wasm-tools-go v0.1.5 h1:ah2WT4gH0IrmN29ZSsjgNC9SPsdXZ+KN+o9uTZqNVSI= 2 | github.com/ydnar/wasm-tools-go v0.1.5/go.mod h1:L3sDi5rbAMJNmMO5cpDRzYYhB0r9xIU0xgpKjwU0Adg= 3 | -------------------------------------------------------------------------------- /lib/http/client/transport.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io" 7 | "net/http" 8 | "net/url" 9 | "strconv" 10 | 11 | outgoinghandler "github.com/dev-wasm/dev-wasm-go/lib/wasi/http/outgoing-handler" 12 | "github.com/dev-wasm/dev-wasm-go/lib/wasi/http/types" 13 | "github.com/ydnar/wasm-tools-go/cm" 14 | ) 15 | 16 | const DEFAULT_USER_AGENT = "WASI-HTTP-Go/0.0.2" 17 | 18 | func OK[Shape, T, Err any](val cm.Result[Shape, T, Err]) *T { 19 | return (&val).OK() 20 | } 21 | 22 | type bytesReaderCloser struct { 23 | *bytes.Reader 24 | } 25 | 26 | // Close implements io.Closer.Close. 27 | func (bytesReaderCloser) Close() error { 28 | return nil 29 | } 30 | 31 | func BodyReaderCloser(b []byte) io.ReadCloser { 32 | return bytesReaderCloser{bytes.NewReader(b)} 33 | } 34 | 35 | func schemeFromString(s string) types.Scheme { 36 | switch s { 37 | case "http": 38 | return types.SchemeHTTP() 39 | case "https": 40 | return types.SchemeHTTPS() 41 | default: 42 | return types.SchemeOther(s) 43 | } 44 | } 45 | 46 | func methodFromString(m string) types.Method { 47 | switch m { 48 | case "GET": 49 | return types.MethodGet() 50 | case "PUT": 51 | return types.MethodPut() 52 | case "POST": 53 | return types.MethodPost() 54 | case "DELETE": 55 | return types.MethodDelete() 56 | case "OPTIONS": 57 | return types.MethodOptions() 58 | case "PATCH": 59 | return types.MethodPatch() 60 | case "CONNECT": 61 | return types.MethodConnect() 62 | case "TRACE": 63 | return types.MethodTrace() 64 | default: 65 | return types.MethodOther(m) 66 | } 67 | } 68 | 69 | func Put(client *http.Client, uri, contentType string, body io.ReadCloser) (*http.Response, error) { 70 | u, e := url.Parse(uri) 71 | if e != nil { 72 | return nil, e 73 | } 74 | req := http.Request{ 75 | Method: "PUT", 76 | URL: u, 77 | Body: body, 78 | Header: make(http.Header), 79 | } 80 | req.Header["Content-type"] = []string{contentType} 81 | return client.Do(&req) 82 | } 83 | 84 | type WasiRoundTripper struct{} 85 | 86 | func initHeaders(r *http.Request) { 87 | if r.Header == nil { 88 | r.Header = http.Header{} 89 | } 90 | if _, ok := r.Header["User-Agent"]; !ok { 91 | r.Header["User-Agent"] = []string{DEFAULT_USER_AGENT} 92 | } 93 | if r.Close { 94 | r.Header["Connection"] = []string{"close"} 95 | } 96 | if r.Body != nil { 97 | if _, ok := r.Header["Content-Length"]; !ok { 98 | if r.ContentLength > 0 { 99 | r.Header["Content-Length"] = []string{strconv.Itoa(int(r.ContentLength))} 100 | } 101 | } 102 | } 103 | } 104 | 105 | func makeHeaders(r *http.Request) cm.List[cm.Tuple[types.FieldKey, types.FieldValue]] { 106 | strstr := []cm.Tuple[types.FieldKey, types.FieldValue]{} 107 | for k, v := range r.Header { 108 | for _, str := range v { 109 | strstr = append( 110 | strstr, 111 | cm.Tuple[types.FieldKey, types.FieldValue]{ 112 | F0: types.FieldKey(k), 113 | F1: types.FieldValue(cm.ToList([]uint8(str))), 114 | }, 115 | ) 116 | } 117 | } 118 | return cm.ToList(strstr) 119 | } 120 | 121 | func getAuthority(r *http.Request) string { 122 | if len(r.Host) > 0 { 123 | return r.Host 124 | } else { 125 | return r.URL.Host 126 | } 127 | } 128 | 129 | func populateResponseHeaders(fields cm.List[cm.Tuple[types.FieldKey, types.FieldValue]], r *http.Response) { 130 | if r.Header == nil { 131 | r.Header = http.Header{} 132 | } 133 | for _, field := range fields.Slice() { 134 | key := string(field.F0) 135 | value := string(field.F1.Slice()) 136 | r.Header[key] = append(r.Header[key], value) 137 | } 138 | } 139 | 140 | func (WasiRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) { 141 | initHeaders(r) 142 | 143 | res := types.FieldsFromList(makeHeaders(r)) 144 | headers := res.OK() 145 | 146 | method := methodFromString(r.Method) 147 | scheme := cm.Some(schemeFromString(r.URL.Scheme)) 148 | 149 | path_with_query := cm.Some(r.URL.RequestURI()) 150 | 151 | authority := cm.Some(getAuthority(r)) 152 | 153 | req := types.NewOutgoingRequest(*headers) 154 | req.SetMethod(method) 155 | req.SetPathWithQuery(path_with_query) 156 | req.SetScheme(scheme) 157 | req.SetAuthority(authority) 158 | 159 | body := OK(req.Body()) 160 | if r.Body != nil { 161 | b, err := io.ReadAll(io.Reader(r.Body)) 162 | if err != nil { 163 | return nil, err 164 | } 165 | s := OK(body.Write()) 166 | s.BlockingWriteAndFlush(cm.ToList([]uint8(b))) 167 | s.ResourceDrop() 168 | } 169 | 170 | hRes := outgoinghandler.Handle(req, cm.None[types.RequestOptions]()) 171 | if !hRes.IsOK() { 172 | panic("Failed to call client.") 173 | } 174 | 175 | types.OutgoingBodyFinish(*body, cm.None[types.Fields]()) 176 | 177 | future := hRes.OK() 178 | defer future.ResourceDrop() 179 | resultOption := future.Get() 180 | if !resultOption.None() { 181 | return nil, fmt.Errorf("result already taken") 182 | } 183 | poll := future.Subscribe() 184 | defer poll.ResourceDrop() 185 | poll.Block() 186 | resultOption = future.Get() 187 | result := resultOption.Some().OK().OK() 188 | defer result.ResourceDrop() 189 | 190 | response := http.Response{ 191 | StatusCode: int(result.Status()), 192 | Header: http.Header{}, 193 | } 194 | 195 | responseHeaders := result.Headers() 196 | entries := responseHeaders.Entries() 197 | populateResponseHeaders(entries, &response) 198 | 199 | responseHeaders.ResourceDrop() 200 | 201 | responseBody := OK(result.Consume()) 202 | defer responseBody.ResourceDrop() 203 | stream := OK(responseBody.Stream()) 204 | defer stream.ResourceDrop() 205 | inputPoll := stream.Subscribe() 206 | defer inputPoll.ResourceDrop() 207 | 208 | data := []uint8{} 209 | for { 210 | inputPoll.Block() 211 | dataResult := stream.Read(64 * 1024) 212 | if dataResult.IsOK() { 213 | data = append(data, dataResult.OK().Slice()...) 214 | } else if dataResult.Err().Closed() { 215 | break 216 | } else { 217 | return nil, fmt.Errorf("error reading response stream") 218 | } 219 | } 220 | 221 | response.Body = bytesReaderCloser{bytes.NewReader(data)} 222 | 223 | return &response, nil 224 | } 225 | -------------------------------------------------------------------------------- /lib/http/client/transport_test.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "bytes" 5 | "net/http" 6 | "net/url" 7 | "reflect" 8 | "testing" 9 | ) 10 | 11 | func TestInitHeader(t *testing.T) { 12 | r := &http.Request{} 13 | initHeaders(r) 14 | 15 | if r.Header == nil { 16 | t.Errorf("expcted non-nil headers") 17 | } 18 | } 19 | 20 | func TestContentLength(t *testing.T) { 21 | r := &http.Request{ 22 | ContentLength: 100, 23 | Body: bytesReaderCloser{bytes.NewReader([]byte{})}, 24 | } 25 | initHeaders(r) 26 | 27 | if !reflect.DeepEqual(r.Header["Content-Length"], []string{"100"}) { 28 | t.Errorf("expected content-length header to be [100], got %s", r.Header["Content-Length"]) 29 | } 30 | } 31 | 32 | func TestConnectionClose(t *testing.T) { 33 | r := &http.Request{ 34 | Close: true, 35 | } 36 | initHeaders(r) 37 | 38 | if !reflect.DeepEqual(r.Header["Connection"], []string{"close"}) { 39 | t.Errorf("expected content-length header to be [close], got %s", r.Header["Content-Length"]) 40 | } 41 | } 42 | 43 | func TestUserAgent(t *testing.T) { 44 | r := &http.Request{} 45 | initHeaders(r) 46 | 47 | if !reflect.DeepEqual(r.Header["User-Agent"], []string{DEFAULT_USER_AGENT}) { 48 | t.Errorf("expected content-length header to be [%s], got %s", DEFAULT_USER_AGENT, r.Header["User-Agent"]) 49 | } 50 | 51 | agent := "Override" 52 | r.Header["User-Agent"] = []string{agent} 53 | if !reflect.DeepEqual(r.Header["User-Agent"], []string{agent}) { 54 | t.Errorf("expected content-length header to be [%s], got %s", agent, r.Header["User-Agent"]) 55 | } 56 | } 57 | 58 | func TestMakeHeaders(t *testing.T) { 59 | r := &http.Request{ 60 | Header: http.Header{ 61 | "User-Agent": []string{"foo"}, 62 | }, 63 | } 64 | 65 | headers := makeHeaders(r) 66 | slice := headers.Slice() 67 | if len(slice) != 1 { 68 | t.Errorf("Unexpected header length") 69 | t.FailNow() 70 | } 71 | if slice[0].F0 != "User-Agent" { 72 | t.Errorf("Unexpected field key: %s", slice[0].F0) 73 | } 74 | byteSlice := slice[0].F1.Slice() 75 | if string(byteSlice) != "foo" { 76 | t.Errorf("Unexpected values: %v", slice[0].F1.Slice()) 77 | } 78 | } 79 | 80 | func TestMakeMultipleHeaders(t *testing.T) { 81 | r := &http.Request{ 82 | Header: http.Header{ 83 | "User-Agent": []string{ 84 | "foo", 85 | "bar", 86 | }, 87 | }, 88 | } 89 | 90 | headers := makeHeaders(r) 91 | slice := headers.Slice() 92 | if len(slice) != 2 { 93 | t.Errorf("Unexpected header length") 94 | t.FailNow() 95 | } 96 | for i := 0; i < 2; i++ { 97 | if slice[i].F0 != "User-Agent" { 98 | t.Errorf("Unexpected field key: %s", slice[0].F0) 99 | } 100 | } 101 | byteSlice := slice[0].F1.Slice() 102 | if string(byteSlice) != "foo" { 103 | t.Errorf("Unexpected values: %v", slice[0].F1.Slice()) 104 | } 105 | byteSlice = slice[1].F1.Slice() 106 | if string(byteSlice) != "bar" { 107 | t.Errorf("Unexpected values: %v", slice[1].F1.Slice()) 108 | } 109 | } 110 | 111 | func TestGetAuthority(t *testing.T) { 112 | u, _ := url.Parse("http://company.com") 113 | authority := getAuthority(&http.Request{ 114 | Host: "foo", 115 | URL: u, 116 | }) 117 | if authority != "foo" { 118 | t.Errorf("unexpected authority: %s", authority) 119 | } 120 | authority = getAuthority(&http.Request{ 121 | URL: u, 122 | }) 123 | if authority != "company.com" { 124 | t.Errorf("unexpected authority: %s", authority) 125 | } 126 | } 127 | 128 | func TestPopulateHeaders(t *testing.T) { 129 | headers := http.Header{ 130 | "Status": []string{"200"}, 131 | "Multi-Value": []string{"foo", "bar"}, 132 | } 133 | r := http.Response{} 134 | populateResponseHeaders(makeHeaders(&http.Request{ 135 | Header: headers, 136 | }), &r) 137 | 138 | if !reflect.DeepEqual(r.Header, headers) { 139 | t.Errorf("unexpected headers: %v", r.Header) 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /lib/http/server/handler/handler.go: -------------------------------------------------------------------------------- 1 | package handler 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "net/http" 7 | "strconv" 8 | 9 | incominghandler "github.com/dev-wasm/dev-wasm-go/lib/wasi/http/incoming-handler" 10 | "github.com/dev-wasm/dev-wasm-go/lib/wasi/http/types" 11 | "github.com/ydnar/wasm-tools-go/cm" 12 | ) 13 | 14 | var h = &handler{ 15 | handler: http.DefaultServeMux, 16 | } 17 | 18 | func OK[Shape, T, Err any](val cm.Result[Shape, T, Err]) *T { 19 | return (&val).OK() 20 | } 21 | 22 | func OKOrPanic[Shape, T, Err any](val cm.Result[Shape, T, Err]) *T { 23 | if !val.IsOK() { 24 | panic(fmt.Sprintf("a value is not OK as expected: %v", val)) 25 | } 26 | return (&val).OK() 27 | } 28 | 29 | func Some[T any](val cm.Option[T]) *T { 30 | return (&val).Some() 31 | } 32 | 33 | func theHandler(req types.IncomingRequest, res types.ResponseOutparam) { 34 | h.Handle(req, res) 35 | } 36 | 37 | func init() { 38 | incominghandler.Exports.Handle = theHandler 39 | } 40 | 41 | func HandleFunc(pattern string, fn http.HandlerFunc) { 42 | http.DefaultServeMux.HandleFunc(pattern, fn) 43 | } 44 | 45 | type handler struct { 46 | handler http.Handler 47 | } 48 | 49 | type wasmResponseWriter struct { 50 | header http.Header 51 | code int 52 | body bytes.Buffer 53 | } 54 | 55 | func (w *wasmResponseWriter) Header() http.Header { 56 | return w.header 57 | } 58 | 59 | func (w *wasmResponseWriter) WriteHeader(code int) { 60 | w.code = code 61 | } 62 | 63 | func (w *wasmResponseWriter) Write(data []byte) (int, error) { 64 | if w.code == 0 { 65 | w.code = http.StatusOK 66 | } 67 | return w.body.Write(data) 68 | } 69 | 70 | func schemeToString(scheme *types.Scheme) string { 71 | if scheme.HTTP() { 72 | return "http" 73 | } 74 | if scheme.HTTPS() { 75 | return "https" 76 | } 77 | return *scheme.Other() 78 | } 79 | 80 | func methodToString(method types.Method) string { 81 | if method.Get() { 82 | return "GET" 83 | } 84 | if method.Put() { 85 | return "PUT" 86 | } 87 | if method.Post() { 88 | return "POST" 89 | } 90 | if method.Patch() { 91 | return "PATCH" 92 | } 93 | if method.Connect() { 94 | return "CONNECT" 95 | } 96 | if method.Delete() { 97 | return "DELETE" 98 | } 99 | if method.Head() { 100 | return "HEAD" 101 | } 102 | if method.Options() { 103 | return "OPTIONS" 104 | } 105 | panic("unsupported method") 106 | } 107 | 108 | func (h *handler) HandleError(msg string, req types.IncomingRequest, responseOut types.ResponseOutparam) { 109 | headers := []cm.Tuple[types.FieldKey, types.FieldValue]{} 110 | hdrs := cm.ToList(headers) 111 | res := types.FieldsFromList(hdrs) 112 | response := types.NewOutgoingResponse(*res.OK()) 113 | response.SetStatusCode(500) 114 | body := OK(response.Body()) 115 | resResult := cm.OK[cm.Result[types.ErrorCodeShape, types.OutgoingResponse, types.ErrorCode]](response) 116 | types.ResponseOutparamSet(responseOut, resResult) 117 | 118 | out := OK(body.Write()) 119 | OKOrPanic(out.BlockingWriteAndFlush(cm.ToList([]uint8(msg)))) 120 | 121 | types.OutgoingBodyFinish(*body, cm.None[types.Fields]()) 122 | } 123 | 124 | func (h *handler) Handle(req types.IncomingRequest, responseOut types.ResponseOutparam) { 125 | defer func() { 126 | if r := recover(); r != nil { 127 | msg := "unknown panic" 128 | switch t := r.(type) { 129 | case string: 130 | msg = t 131 | case error: 132 | msg = t.Error() 133 | default: 134 | // pass 135 | } 136 | h.HandleError(msg, req, responseOut) 137 | } 138 | }() 139 | 140 | scheme := Some(req.Scheme()) 141 | authority := Some(req.Authority()) 142 | path := Some(req.PathWithQuery()) 143 | urlString := fmt.Sprintf("%s://%s%s", schemeToString(scheme), *authority, *path) 144 | method := req.Method() 145 | 146 | requestBody := OK(req.Consume()) 147 | bodyStream := OK(requestBody.Stream()) 148 | 149 | var buff []byte 150 | for { 151 | readResult := bodyStream.BlockingRead(1024 * 1024) 152 | if readResult.IsErr() { 153 | if readResult.Err().Closed() { 154 | break 155 | } else { 156 | h.HandleError("Reading body failed!", req, responseOut) 157 | return 158 | } 159 | } else { 160 | bytes := readResult.OK().Slice() 161 | buff = append(buff, bytes...) 162 | } 163 | } 164 | bodyStream.ResourceDrop() 165 | requestBody.ResourceDrop() 166 | 167 | fields := req.Headers() 168 | header := http.Header{} 169 | for _, tuple := range fields.Entries().Slice() { 170 | header[string(tuple.F0)] = append(header[string(tuple.F0)], string(tuple.F1.Slice())) 171 | } 172 | 173 | fields.ResourceDrop() 174 | req.ResourceDrop() 175 | 176 | goReq, err := http.NewRequest(methodToString(method), urlString, bytes.NewBuffer(buff)) 177 | if err != nil { 178 | h.HandleError(err.Error(), req, responseOut) 179 | return 180 | } 181 | goReq.Header = header 182 | if length, ok := header["Content-Length"]; ok { 183 | if contentLength, err := strconv.Atoi(length[0]); err == nil { 184 | goReq.ContentLength = int64(contentLength) 185 | } 186 | } 187 | goRes := wasmResponseWriter{ 188 | header: http.Header{}, 189 | code: -1, 190 | body: bytes.Buffer{}, 191 | } 192 | h.handler.ServeHTTP(&goRes, goReq) 193 | 194 | headers := []cm.Tuple[types.FieldKey, types.FieldValue]{} 195 | for key, val := range goRes.header { 196 | for ix := range val { 197 | headers = append(headers, cm.Tuple[types.FieldKey, types.FieldValue]{ 198 | F0: types.FieldKey(key), 199 | F1: types.FieldValue(cm.ToList([]uint8(val[ix]))), 200 | }) 201 | } 202 | } 203 | f := OK(types.FieldsFromList(cm.ToList(headers))) 204 | 205 | res := types.NewOutgoingResponse(*f) 206 | res.SetStatusCode(types.StatusCode(goRes.code)) 207 | body := OK(res.Body()) 208 | 209 | result := cm.OK[cm.Result[types.ErrorCodeShape, types.OutgoingResponse, types.ErrorCode]](res) 210 | 211 | types.ResponseOutparamSet(responseOut, result) 212 | 213 | stream := OK(body.Write()) 214 | stream.BlockingWriteAndFlush(cm.ToList([]byte(goRes.body.Bytes()))) 215 | stream.ResourceDrop() 216 | 217 | types.OutgoingBodyFinish(*body, cm.None[types.Fields]()) 218 | } 219 | 220 | func ListenAndServe(handler http.Handler) error { 221 | if handler != nil { 222 | h.handler = handler 223 | } 224 | return nil 225 | } 226 | -------------------------------------------------------------------------------- /lib/http/server/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | 7 | "github.com/dev-wasm/dev-wasm-go/lib/http/server/handler" 8 | ) 9 | 10 | var count = 0 11 | 12 | func main() { 13 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 14 | w.Header().Add("Server", "WASM-Test 0.0.1") 15 | w.Header().Add("Content-Type", "text/plain") 16 | w.WriteHeader(200) 17 | body := fmt.Sprintf("Hello from WASM! (%d)", count) 18 | count = count + 1 19 | w.Write([]byte(body)) 20 | }) 21 | handler.ListenAndServe(nil) 22 | } 23 | -------------------------------------------------------------------------------- /lib/wasi/.gitignore: -------------------------------------------------------------------------------- 1 | wasi-http/ 2 | -------------------------------------------------------------------------------- /lib/wasi/Makefile: -------------------------------------------------------------------------------- 1 | .phony: gen clean run 2 | 3 | default: wasi-http 4 | 5 | wasi-http: ; git clone https://github.com/WebAssembly/wasi-http; cd wasi-http; git checkout v0.2.0 ; cd ../ ; cp wasi.wit wasi-http/wit 6 | 7 | gen: wasi-http ; cd ../ ; wit-bindgen-go generate wasi/wasi-http/wit 8 | 9 | clean: ; rm -rf wasi-http -------------------------------------------------------------------------------- /lib/wasi/cli/run/empty.s: -------------------------------------------------------------------------------- 1 | // This file exists for testing this package without WebAssembly, 2 | // allowing empty function bodies with a //go:wasmimport directive. 3 | // See https://pkg.go.dev/cmd/compile for more information. 4 | -------------------------------------------------------------------------------- /lib/wasi/cli/run/run.exports.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | package run 4 | 5 | import ( 6 | "github.com/ydnar/wasm-tools-go/cm" 7 | ) 8 | 9 | // Exports represents the caller-defined exports from "wasi:cli/run@0.2.0". 10 | var Exports struct { 11 | // Run represents the caller-defined, exported function "run". 12 | // 13 | // Run the program. 14 | // 15 | // run: func() -> result 16 | Run func() (result cm.BoolResult) 17 | } 18 | -------------------------------------------------------------------------------- /lib/wasi/cli/run/run.wit.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | // Package run represents the exported interface "wasi:cli/run@0.2.0". 4 | package run 5 | 6 | import ( 7 | "github.com/ydnar/wasm-tools-go/cm" 8 | ) 9 | 10 | //go:wasmexport wasi:cli/run@0.2.0#run 11 | //export wasi:cli/run@0.2.0#run 12 | func wasmexport_Run() (result0 uint32) { 13 | result := Exports.Run() 14 | result0 = cm.BoolToU32(result) 15 | return 16 | } 17 | -------------------------------------------------------------------------------- /lib/wasi/cli/stderr/empty.s: -------------------------------------------------------------------------------- 1 | // This file exists for testing this package without WebAssembly, 2 | // allowing empty function bodies with a //go:wasmimport directive. 3 | // See https://pkg.go.dev/cmd/compile for more information. 4 | -------------------------------------------------------------------------------- /lib/wasi/cli/stderr/stderr.wit.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | // Package stderr represents the imported interface "wasi:cli/stderr@0.2.0". 4 | package stderr 5 | 6 | import ( 7 | "github.com/dev-wasm/dev-wasm-go/lib/wasi/io/streams" 8 | "github.com/ydnar/wasm-tools-go/cm" 9 | ) 10 | 11 | // GetStderr represents the imported function "get-stderr". 12 | // 13 | // get-stderr: func() -> output-stream 14 | // 15 | //go:nosplit 16 | func GetStderr() (result streams.OutputStream) { 17 | result0 := wasmimport_GetStderr() 18 | result = cm.Reinterpret[streams.OutputStream]((uint32)(result0)) 19 | return 20 | } 21 | 22 | //go:wasmimport wasi:cli/stderr@0.2.0 get-stderr 23 | //go:noescape 24 | func wasmimport_GetStderr() (result0 uint32) 25 | -------------------------------------------------------------------------------- /lib/wasi/cli/stdin/empty.s: -------------------------------------------------------------------------------- 1 | // This file exists for testing this package without WebAssembly, 2 | // allowing empty function bodies with a //go:wasmimport directive. 3 | // See https://pkg.go.dev/cmd/compile for more information. 4 | -------------------------------------------------------------------------------- /lib/wasi/cli/stdin/stdin.wit.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | // Package stdin represents the imported interface "wasi:cli/stdin@0.2.0". 4 | package stdin 5 | 6 | import ( 7 | "github.com/dev-wasm/dev-wasm-go/lib/wasi/io/streams" 8 | "github.com/ydnar/wasm-tools-go/cm" 9 | ) 10 | 11 | // GetStdin represents the imported function "get-stdin". 12 | // 13 | // get-stdin: func() -> input-stream 14 | // 15 | //go:nosplit 16 | func GetStdin() (result streams.InputStream) { 17 | result0 := wasmimport_GetStdin() 18 | result = cm.Reinterpret[streams.InputStream]((uint32)(result0)) 19 | return 20 | } 21 | 22 | //go:wasmimport wasi:cli/stdin@0.2.0 get-stdin 23 | //go:noescape 24 | func wasmimport_GetStdin() (result0 uint32) 25 | -------------------------------------------------------------------------------- /lib/wasi/cli/stdout/empty.s: -------------------------------------------------------------------------------- 1 | // This file exists for testing this package without WebAssembly, 2 | // allowing empty function bodies with a //go:wasmimport directive. 3 | // See https://pkg.go.dev/cmd/compile for more information. 4 | -------------------------------------------------------------------------------- /lib/wasi/cli/stdout/stdout.wit.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | // Package stdout represents the imported interface "wasi:cli/stdout@0.2.0". 4 | package stdout 5 | 6 | import ( 7 | "github.com/dev-wasm/dev-wasm-go/lib/wasi/io/streams" 8 | "github.com/ydnar/wasm-tools-go/cm" 9 | ) 10 | 11 | // GetStdout represents the imported function "get-stdout". 12 | // 13 | // get-stdout: func() -> output-stream 14 | // 15 | //go:nosplit 16 | func GetStdout() (result streams.OutputStream) { 17 | result0 := wasmimport_GetStdout() 18 | result = cm.Reinterpret[streams.OutputStream]((uint32)(result0)) 19 | return 20 | } 21 | 22 | //go:wasmimport wasi:cli/stdout@0.2.0 get-stdout 23 | //go:noescape 24 | func wasmimport_GetStdout() (result0 uint32) 25 | -------------------------------------------------------------------------------- /lib/wasi/clocks/monotonic-clock/empty.s: -------------------------------------------------------------------------------- 1 | // This file exists for testing this package without WebAssembly, 2 | // allowing empty function bodies with a //go:wasmimport directive. 3 | // See https://pkg.go.dev/cmd/compile for more information. 4 | -------------------------------------------------------------------------------- /lib/wasi/clocks/monotonic-clock/monotonic-clock.wit.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | // Package monotonicclock represents the imported interface "wasi:clocks/monotonic-clock@0.2.0". 4 | // 5 | // WASI Monotonic Clock is a clock API intended to let users measure elapsed 6 | // time. 7 | // 8 | // It is intended to be portable at least between Unix-family platforms and 9 | // Windows. 10 | // 11 | // A monotonic clock is a clock which has an unspecified initial value, and 12 | // successive reads of the clock will produce non-decreasing values. 13 | // 14 | // It is intended for measuring elapsed time. 15 | package monotonicclock 16 | 17 | import ( 18 | "github.com/dev-wasm/dev-wasm-go/lib/wasi/io/poll" 19 | "github.com/ydnar/wasm-tools-go/cm" 20 | ) 21 | 22 | // Instant represents the u64 "wasi:clocks/monotonic-clock@0.2.0#instant". 23 | // 24 | // An instant in time, in nanoseconds. An instant is relative to an 25 | // unspecified initial value, and can only be compared to instances from 26 | // the same monotonic-clock. 27 | // 28 | // type instant = u64 29 | type Instant uint64 30 | 31 | // Duration represents the u64 "wasi:clocks/monotonic-clock@0.2.0#duration". 32 | // 33 | // A duration of time, in nanoseconds. 34 | // 35 | // type duration = u64 36 | type Duration uint64 37 | 38 | // Now represents the imported function "now". 39 | // 40 | // Read the current value of the clock. 41 | // 42 | // The clock is monotonic, therefore calling this function repeatedly will 43 | // produce a sequence of non-decreasing values. 44 | // 45 | // now: func() -> instant 46 | // 47 | //go:nosplit 48 | func Now() (result Instant) { 49 | result0 := wasmimport_Now() 50 | result = (Instant)((uint64)(result0)) 51 | return 52 | } 53 | 54 | //go:wasmimport wasi:clocks/monotonic-clock@0.2.0 now 55 | //go:noescape 56 | func wasmimport_Now() (result0 uint64) 57 | 58 | // Resolution represents the imported function "resolution". 59 | // 60 | // Query the resolution of the clock. Returns the duration of time 61 | // corresponding to a clock tick. 62 | // 63 | // resolution: func() -> duration 64 | // 65 | //go:nosplit 66 | func Resolution() (result Duration) { 67 | result0 := wasmimport_Resolution() 68 | result = (Duration)((uint64)(result0)) 69 | return 70 | } 71 | 72 | //go:wasmimport wasi:clocks/monotonic-clock@0.2.0 resolution 73 | //go:noescape 74 | func wasmimport_Resolution() (result0 uint64) 75 | 76 | // SubscribeInstant represents the imported function "subscribe-instant". 77 | // 78 | // Create a `pollable` which will resolve once the specified instant 79 | // occured. 80 | // 81 | // subscribe-instant: func(when: instant) -> pollable 82 | // 83 | //go:nosplit 84 | func SubscribeInstant(when Instant) (result poll.Pollable) { 85 | when0 := (uint64)(when) 86 | result0 := wasmimport_SubscribeInstant((uint64)(when0)) 87 | result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) 88 | return 89 | } 90 | 91 | //go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-instant 92 | //go:noescape 93 | func wasmimport_SubscribeInstant(when0 uint64) (result0 uint32) 94 | 95 | // SubscribeDuration represents the imported function "subscribe-duration". 96 | // 97 | // Create a `pollable` which will resolve once the given duration has 98 | // elapsed, starting at the time at which this function was called. 99 | // occured. 100 | // 101 | // subscribe-duration: func(when: duration) -> pollable 102 | // 103 | //go:nosplit 104 | func SubscribeDuration(when Duration) (result poll.Pollable) { 105 | when0 := (uint64)(when) 106 | result0 := wasmimport_SubscribeDuration((uint64)(when0)) 107 | result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) 108 | return 109 | } 110 | 111 | //go:wasmimport wasi:clocks/monotonic-clock@0.2.0 subscribe-duration 112 | //go:noescape 113 | func wasmimport_SubscribeDuration(when0 uint64) (result0 uint32) 114 | -------------------------------------------------------------------------------- /lib/wasi/clocks/wall-clock/empty.s: -------------------------------------------------------------------------------- 1 | // This file exists for testing this package without WebAssembly, 2 | // allowing empty function bodies with a //go:wasmimport directive. 3 | // See https://pkg.go.dev/cmd/compile for more information. 4 | -------------------------------------------------------------------------------- /lib/wasi/clocks/wall-clock/wall-clock.wit.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | // Package wallclock represents the imported interface "wasi:clocks/wall-clock@0.2.0". 4 | // 5 | // WASI Wall Clock is a clock API intended to let users query the current 6 | // time. The name "wall" makes an analogy to a "clock on the wall", which 7 | // is not necessarily monotonic as it may be reset. 8 | // 9 | // It is intended to be portable at least between Unix-family platforms and 10 | // Windows. 11 | // 12 | // A wall clock is a clock which measures the date and time according to 13 | // some external reference. 14 | // 15 | // External references may be reset, so this clock is not necessarily 16 | // monotonic, making it unsuitable for measuring elapsed time. 17 | // 18 | // It is intended for reporting the current date and time for humans. 19 | package wallclock 20 | 21 | // DateTime represents the record "wasi:clocks/wall-clock@0.2.0#datetime". 22 | // 23 | // A time and date in seconds plus nanoseconds. 24 | // 25 | // record datetime { 26 | // seconds: u64, 27 | // nanoseconds: u32, 28 | // } 29 | type DateTime struct { 30 | Seconds uint64 31 | Nanoseconds uint32 32 | } 33 | 34 | // Now represents the imported function "now". 35 | // 36 | // Read the current value of the clock. 37 | // 38 | // This clock is not monotonic, therefore calling this function repeatedly 39 | // will not necessarily produce a sequence of non-decreasing values. 40 | // 41 | // The returned timestamps represent the number of seconds since 42 | // 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], 43 | // also known as [Unix Time]. 44 | // 45 | // The nanoseconds field of the output is always less than 1000000000. 46 | // 47 | // now: func() -> datetime 48 | // 49 | // [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 50 | // [Unix Time]: https://en.wikipedia.org/wiki/Unix_time 51 | // 52 | //go:nosplit 53 | func Now() (result DateTime) { 54 | wasmimport_Now(&result) 55 | return 56 | } 57 | 58 | //go:wasmimport wasi:clocks/wall-clock@0.2.0 now 59 | //go:noescape 60 | func wasmimport_Now(result *DateTime) 61 | 62 | // Resolution represents the imported function "resolution". 63 | // 64 | // Query the resolution of the clock. 65 | // 66 | // The nanoseconds field of the output is always less than 1000000000. 67 | // 68 | // resolution: func() -> datetime 69 | // 70 | //go:nosplit 71 | func Resolution() (result DateTime) { 72 | wasmimport_Resolution(&result) 73 | return 74 | } 75 | 76 | //go:wasmimport wasi:clocks/wall-clock@0.2.0 resolution 77 | //go:noescape 78 | func wasmimport_Resolution(result *DateTime) 79 | -------------------------------------------------------------------------------- /lib/wasi/http/incoming-handler/empty.s: -------------------------------------------------------------------------------- 1 | // This file exists for testing this package without WebAssembly, 2 | // allowing empty function bodies with a //go:wasmimport directive. 3 | // See https://pkg.go.dev/cmd/compile for more information. 4 | -------------------------------------------------------------------------------- /lib/wasi/http/incoming-handler/incoming-handler.exports.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | package incominghandler 4 | 5 | import ( 6 | "github.com/dev-wasm/dev-wasm-go/lib/wasi/http/types" 7 | ) 8 | 9 | // Exports represents the caller-defined exports from "wasi:http/incoming-handler@0.2.0". 10 | var Exports struct { 11 | // Handle represents the caller-defined, exported function "handle". 12 | // 13 | // This function is invoked with an incoming HTTP Request, and a resource 14 | // `response-outparam` which provides the capability to reply with an HTTP 15 | // Response. The response is sent by calling the `response-outparam.set` 16 | // method, which allows execution to continue after the response has been 17 | // sent. This enables both streaming to the response body, and performing other 18 | // work. 19 | // 20 | // The implementor of this function must write a response to the 21 | // `response-outparam` before returning, or else the caller will respond 22 | // with an error on its behalf. 23 | // 24 | // handle: func(request: incoming-request, response-out: response-outparam) 25 | Handle func(request types.IncomingRequest, responseOut types.ResponseOutparam) 26 | } 27 | -------------------------------------------------------------------------------- /lib/wasi/http/incoming-handler/incoming-handler.wit.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | // Package incominghandler represents the exported interface "wasi:http/incoming-handler@0.2.0". 4 | // 5 | // This interface defines a handler of incoming HTTP Requests. It should 6 | // be exported by components which can respond to HTTP Requests. 7 | package incominghandler 8 | 9 | import ( 10 | "github.com/dev-wasm/dev-wasm-go/lib/wasi/http/types" 11 | "github.com/ydnar/wasm-tools-go/cm" 12 | ) 13 | 14 | //go:wasmexport wasi:http/incoming-handler@0.2.0#handle 15 | //export wasi:http/incoming-handler@0.2.0#handle 16 | func wasmexport_Handle(request0 uint32, responseOut0 uint32) { 17 | request := cm.Reinterpret[types.IncomingRequest]((uint32)(request0)) 18 | responseOut := cm.Reinterpret[types.ResponseOutparam]((uint32)(responseOut0)) 19 | Exports.Handle(request, responseOut) 20 | return 21 | } 22 | -------------------------------------------------------------------------------- /lib/wasi/http/outgoing-handler/abi.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | package outgoinghandler 4 | 5 | import ( 6 | "github.com/dev-wasm/dev-wasm-go/lib/wasi/http/types" 7 | "github.com/ydnar/wasm-tools-go/cm" 8 | "unsafe" 9 | ) 10 | 11 | // ErrorCodeShape is used for storage in variant or result types. 12 | type ErrorCodeShape struct { 13 | shape [unsafe.Sizeof(types.ErrorCode{})]byte 14 | } 15 | 16 | func lower_OptionRequestOptions(v cm.Option[types.RequestOptions]) (f0 uint32, f1 uint32) { 17 | some := v.Some() 18 | if some != nil { 19 | f0 = 1 20 | v1 := cm.Reinterpret[uint32](*some) 21 | f1 = (uint32)(v1) 22 | } 23 | return 24 | } 25 | -------------------------------------------------------------------------------- /lib/wasi/http/outgoing-handler/empty.s: -------------------------------------------------------------------------------- 1 | // This file exists for testing this package without WebAssembly, 2 | // allowing empty function bodies with a //go:wasmimport directive. 3 | // See https://pkg.go.dev/cmd/compile for more information. 4 | -------------------------------------------------------------------------------- /lib/wasi/http/outgoing-handler/outgoing-handler.wit.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | // Package outgoinghandler represents the imported interface "wasi:http/outgoing-handler@0.2.0". 4 | // 5 | // This interface defines a handler of outgoing HTTP Requests. It should be 6 | // imported by components which wish to make HTTP Requests. 7 | package outgoinghandler 8 | 9 | import ( 10 | "github.com/dev-wasm/dev-wasm-go/lib/wasi/http/types" 11 | "github.com/ydnar/wasm-tools-go/cm" 12 | ) 13 | 14 | // Handle represents the imported function "handle". 15 | // 16 | // This function is invoked with an outgoing HTTP Request, and it returns 17 | // a resource `future-incoming-response` which represents an HTTP Response 18 | // which may arrive in the future. 19 | // 20 | // The `options` argument accepts optional parameters for the HTTP 21 | // protocol's transport layer. 22 | // 23 | // This function may return an error if the `outgoing-request` is invalid 24 | // or not allowed to be made. Otherwise, protocol errors are reported 25 | // through the `future-incoming-response`. 26 | // 27 | // handle: func(request: outgoing-request, options: option) -> result 29 | // 30 | //go:nosplit 31 | func Handle(request types.OutgoingRequest, options cm.Option[types.RequestOptions]) (result cm.Result[ErrorCodeShape, types.FutureIncomingResponse, types.ErrorCode]) { 32 | request0 := cm.Reinterpret[uint32](request) 33 | options0, options1 := lower_OptionRequestOptions(options) 34 | wasmimport_Handle((uint32)(request0), (uint32)(options0), (uint32)(options1), &result) 35 | return 36 | } 37 | 38 | //go:wasmimport wasi:http/outgoing-handler@0.2.0 handle 39 | //go:noescape 40 | func wasmimport_Handle(request0 uint32, options0 uint32, options1 uint32, result *cm.Result[ErrorCodeShape, types.FutureIncomingResponse, types.ErrorCode]) 41 | -------------------------------------------------------------------------------- /lib/wasi/http/types/abi.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | package types 4 | 5 | import ( 6 | monotonicclock "github.com/dev-wasm/dev-wasm-go/lib/wasi/clocks/monotonic-clock" 7 | "github.com/ydnar/wasm-tools-go/cm" 8 | "unsafe" 9 | ) 10 | 11 | // OptionFieldSizePayloadShape is used for storage in variant or result types. 12 | type OptionFieldSizePayloadShape struct { 13 | shape [unsafe.Sizeof(cm.Option[FieldSizePayload]{})]byte 14 | } 15 | 16 | func lower_OptionString(v cm.Option[string]) (f0 uint32, f1 *uint8, f2 uint32) { 17 | some := v.Some() 18 | if some != nil { 19 | f0 = 1 20 | v1, v2 := cm.LowerString(*some) 21 | f1 = (*uint8)(v1) 22 | f2 = (uint32)(v2) 23 | } 24 | return 25 | } 26 | 27 | func lower_Method(v Method) (f0 uint32, f1 *uint8, f2 uint32) { 28 | f0 = (uint32)(v.Tag()) 29 | switch f0 { 30 | case 9: // other 31 | v1, v2 := cm.LowerString(*v.Other()) 32 | f1 = (*uint8)(v1) 33 | f2 = (uint32)(v2) 34 | } 35 | return 36 | } 37 | 38 | func lower_Scheme(v Scheme) (f0 uint32, f1 *uint8, f2 uint32) { 39 | f0 = (uint32)(v.Tag()) 40 | switch f0 { 41 | case 2: // other 42 | v1, v2 := cm.LowerString(*v.Other()) 43 | f1 = (*uint8)(v1) 44 | f2 = (uint32)(v2) 45 | } 46 | return 47 | } 48 | 49 | func lower_OptionScheme(v cm.Option[Scheme]) (f0 uint32, f1 uint32, f2 *uint8, f3 uint32) { 50 | some := v.Some() 51 | if some != nil { 52 | f0 = 1 53 | v1, v2, v3 := lower_Scheme(*some) 54 | f1 = (uint32)(v1) 55 | f2 = (*uint8)(v2) 56 | f3 = (uint32)(v3) 57 | } 58 | return 59 | } 60 | 61 | func lower_OptionDuration(v cm.Option[monotonicclock.Duration]) (f0 uint32, f1 uint64) { 62 | some := v.Some() 63 | if some != nil { 64 | f0 = 1 65 | v1 := (uint64)(*some) 66 | f1 = (uint64)(v1) 67 | } 68 | return 69 | } 70 | 71 | // ErrorCodeShape is used for storage in variant or result types. 72 | type ErrorCodeShape struct { 73 | shape [unsafe.Sizeof(ErrorCode{})]byte 74 | } 75 | 76 | func lower_OptionU16(v cm.Option[uint16]) (f0 uint32, f1 uint32) { 77 | some := v.Some() 78 | if some != nil { 79 | f0 = 1 80 | v1 := (uint32)(*some) 81 | f1 = (uint32)(v1) 82 | } 83 | return 84 | } 85 | 86 | func lower_DNSErrorPayload(v DNSErrorPayload) (f0 uint32, f1 *uint8, f2 uint32, f3 uint32, f4 uint32) { 87 | f0, f1, f2 = lower_OptionString(v.Rcode) 88 | f3, f4 = lower_OptionU16(v.InfoCode) 89 | return 90 | } 91 | 92 | func lower_OptionU8(v cm.Option[uint8]) (f0 uint32, f1 uint32) { 93 | some := v.Some() 94 | if some != nil { 95 | f0 = 1 96 | v1 := (uint32)(*some) 97 | f1 = (uint32)(v1) 98 | } 99 | return 100 | } 101 | 102 | func lower_TLSAlertReceivedPayload(v TLSAlertReceivedPayload) (f0 uint32, f1 uint32, f2 uint32, f3 *uint8, f4 uint32) { 103 | f0, f1 = lower_OptionU8(v.AlertID) 104 | f2, f3, f4 = lower_OptionString(v.AlertMessage) 105 | return 106 | } 107 | 108 | func lower_OptionU64(v cm.Option[uint64]) (f0 uint32, f1 uint64) { 109 | some := v.Some() 110 | if some != nil { 111 | f0 = 1 112 | v1 := (uint64)(*some) 113 | f1 = (uint64)(v1) 114 | } 115 | return 116 | } 117 | 118 | func lower_OptionU32(v cm.Option[uint32]) (f0 uint32, f1 uint32) { 119 | some := v.Some() 120 | if some != nil { 121 | f0 = 1 122 | v1 := (uint32)(*some) 123 | f1 = (uint32)(v1) 124 | } 125 | return 126 | } 127 | 128 | func lower_FieldSizePayload(v FieldSizePayload) (f0 uint32, f1 *uint8, f2 uint32, f3 uint32, f4 uint32) { 129 | f0, f1, f2 = lower_OptionString(v.FieldName) 130 | f3, f4 = lower_OptionU32(v.FieldSize) 131 | return 132 | } 133 | 134 | func lower_OptionFieldSizePayload(v cm.Option[FieldSizePayload]) (f0 uint32, f1 uint32, f2 *uint8, f3 uint32, f4 uint32, f5 uint32) { 135 | some := v.Some() 136 | if some != nil { 137 | f0 = 1 138 | v1, v2, v3, v4, v5 := lower_FieldSizePayload(*some) 139 | f1 = (uint32)(v1) 140 | f2 = (*uint8)(v2) 141 | f3 = (uint32)(v3) 142 | f4 = (uint32)(v4) 143 | f5 = (uint32)(v5) 144 | } 145 | return 146 | } 147 | 148 | func lower_ErrorCode(v ErrorCode) (f0 uint32, f1 uint32, f2 uint64, f3 uint32, f4 uint32, f5 uint32, f6 uint32) { 149 | f0 = (uint32)(v.Tag()) 150 | switch f0 { 151 | case 1: // DNS-error 152 | v1, v2, v3, v4, v5 := lower_DNSErrorPayload(*v.DNSError()) 153 | f1 = (uint32)(v1) 154 | f2 = cm.PointerToU64(v2) 155 | f3 = (uint32)(v3) 156 | f4 = (uint32)(v4) 157 | f5 = (uint32)(v5) 158 | case 14: // TLS-alert-received 159 | v1, v2, v3, v4, v5 := lower_TLSAlertReceivedPayload(*v.TLSAlertReceived()) 160 | f1 = (uint32)(v1) 161 | f2 = (uint64)(v2) 162 | f3 = (uint32)(v3) 163 | f4 = cm.PointerToU32(v4) 164 | f5 = (uint32)(v5) 165 | case 17: // HTTP-request-body-size 166 | v1, v2 := lower_OptionU64(*v.HTTPRequestBodySize()) 167 | f1 = (uint32)(v1) 168 | f2 = (uint64)(v2) 169 | case 21: // HTTP-request-header-section-size 170 | v1, v2 := lower_OptionU32(*v.HTTPRequestHeaderSectionSize()) 171 | f1 = (uint32)(v1) 172 | f2 = (uint64)(v2) 173 | case 22: // HTTP-request-header-size 174 | v1, v2, v3, v4, v5, v6 := lower_OptionFieldSizePayload(*v.HTTPRequestHeaderSize()) 175 | f1 = (uint32)(v1) 176 | f2 = (uint64)(v2) 177 | f3 = cm.PointerToU32(v3) 178 | f4 = (uint32)(v4) 179 | f5 = (uint32)(v5) 180 | f6 = (uint32)(v6) 181 | case 23: // HTTP-request-trailer-section-size 182 | v1, v2 := lower_OptionU32(*v.HTTPRequestTrailerSectionSize()) 183 | f1 = (uint32)(v1) 184 | f2 = (uint64)(v2) 185 | case 24: // HTTP-request-trailer-size 186 | v1, v2, v3, v4, v5 := lower_FieldSizePayload(*v.HTTPRequestTrailerSize()) 187 | f1 = (uint32)(v1) 188 | f2 = cm.PointerToU64(v2) 189 | f3 = (uint32)(v3) 190 | f4 = (uint32)(v4) 191 | f5 = (uint32)(v5) 192 | case 26: // HTTP-response-header-section-size 193 | v1, v2 := lower_OptionU32(*v.HTTPResponseHeaderSectionSize()) 194 | f1 = (uint32)(v1) 195 | f2 = (uint64)(v2) 196 | case 27: // HTTP-response-header-size 197 | v1, v2, v3, v4, v5 := lower_FieldSizePayload(*v.HTTPResponseHeaderSize()) 198 | f1 = (uint32)(v1) 199 | f2 = cm.PointerToU64(v2) 200 | f3 = (uint32)(v3) 201 | f4 = (uint32)(v4) 202 | f5 = (uint32)(v5) 203 | case 28: // HTTP-response-body-size 204 | v1, v2 := lower_OptionU64(*v.HTTPResponseBodySize()) 205 | f1 = (uint32)(v1) 206 | f2 = (uint64)(v2) 207 | case 29: // HTTP-response-trailer-section-size 208 | v1, v2 := lower_OptionU32(*v.HTTPResponseTrailerSectionSize()) 209 | f1 = (uint32)(v1) 210 | f2 = (uint64)(v2) 211 | case 30: // HTTP-response-trailer-size 212 | v1, v2, v3, v4, v5 := lower_FieldSizePayload(*v.HTTPResponseTrailerSize()) 213 | f1 = (uint32)(v1) 214 | f2 = cm.PointerToU64(v2) 215 | f3 = (uint32)(v3) 216 | f4 = (uint32)(v4) 217 | f5 = (uint32)(v5) 218 | case 31: // HTTP-response-transfer-coding 219 | v1, v2, v3 := lower_OptionString(*v.HTTPResponseTransferCoding()) 220 | f1 = (uint32)(v1) 221 | f2 = cm.PointerToU64(v2) 222 | f3 = (uint32)(v3) 223 | case 32: // HTTP-response-content-coding 224 | v1, v2, v3 := lower_OptionString(*v.HTTPResponseContentCoding()) 225 | f1 = (uint32)(v1) 226 | f2 = cm.PointerToU64(v2) 227 | f3 = (uint32)(v3) 228 | case 38: // internal-error 229 | v1, v2, v3 := lower_OptionString(*v.InternalError()) 230 | f1 = (uint32)(v1) 231 | f2 = cm.PointerToU64(v2) 232 | f3 = (uint32)(v3) 233 | } 234 | return 235 | } 236 | 237 | func lower_ResultOutgoingResponseErrorCode(v cm.Result[ErrorCodeShape, OutgoingResponse, ErrorCode]) (f0 uint32, f1 uint32, f2 uint32, f3 uint64, f4 uint32, f5 uint32, f6 uint32, f7 uint32) { 238 | if v.IsOK() { 239 | v1 := cm.Reinterpret[uint32](*v.OK()) 240 | f1 = (uint32)(v1) 241 | } else { 242 | f0 = 1 243 | v1, v2, v3, v4, v5, v6, v7 := lower_ErrorCode(*v.Err()) 244 | f1 = (uint32)(v1) 245 | f2 = (uint32)(v2) 246 | f3 = (uint64)(v3) 247 | f4 = (uint32)(v4) 248 | f5 = (uint32)(v5) 249 | f6 = (uint32)(v6) 250 | f7 = (uint32)(v7) 251 | } 252 | return 253 | } 254 | 255 | // ResultOptionTrailersErrorCodeShape is used for storage in variant or result types. 256 | type ResultOptionTrailersErrorCodeShape struct { 257 | shape [unsafe.Sizeof(cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode]{})]byte 258 | } 259 | 260 | func lower_OptionTrailers(v cm.Option[Fields]) (f0 uint32, f1 uint32) { 261 | some := v.Some() 262 | if some != nil { 263 | f0 = 1 264 | v1 := cm.Reinterpret[uint32](*some) 265 | f1 = (uint32)(v1) 266 | } 267 | return 268 | } 269 | 270 | // ResultIncomingResponseErrorCodeShape is used for storage in variant or result types. 271 | type ResultIncomingResponseErrorCodeShape struct { 272 | shape [unsafe.Sizeof(cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode]{})]byte 273 | } 274 | -------------------------------------------------------------------------------- /lib/wasi/http/types/empty.s: -------------------------------------------------------------------------------- 1 | // This file exists for testing this package without WebAssembly, 2 | // allowing empty function bodies with a //go:wasmimport directive. 3 | // See https://pkg.go.dev/cmd/compile for more information. 4 | -------------------------------------------------------------------------------- /lib/wasi/http/types/types.wit.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | // Package types represents the imported interface "wasi:http/types@0.2.0". 4 | // 5 | // This interface defines all of the types and methods for implementing 6 | // HTTP Requests and Responses, both incoming and outgoing, as well as 7 | // their headers, trailers, and bodies. 8 | package types 9 | 10 | import ( 11 | monotonicclock "github.com/dev-wasm/dev-wasm-go/lib/wasi/clocks/monotonic-clock" 12 | ioerror "github.com/dev-wasm/dev-wasm-go/lib/wasi/io/error" 13 | "github.com/dev-wasm/dev-wasm-go/lib/wasi/io/poll" 14 | "github.com/dev-wasm/dev-wasm-go/lib/wasi/io/streams" 15 | "github.com/ydnar/wasm-tools-go/cm" 16 | ) 17 | 18 | // Method represents the variant "wasi:http/types@0.2.0#method". 19 | // 20 | // This type corresponds to HTTP standard Methods. 21 | // 22 | // variant method { 23 | // get, 24 | // head, 25 | // post, 26 | // put, 27 | // delete, 28 | // connect, 29 | // options, 30 | // trace, 31 | // patch, 32 | // other(string), 33 | // } 34 | type Method cm.Variant[uint8, string, string] 35 | 36 | // MethodGet returns a [Method] of case "get". 37 | func MethodGet() Method { 38 | var data struct{} 39 | return cm.New[Method](0, data) 40 | } 41 | 42 | // Get returns true if [Method] represents the variant case "get". 43 | func (self *Method) Get() bool { 44 | return self.Tag() == 0 45 | } 46 | 47 | // MethodHead returns a [Method] of case "head". 48 | func MethodHead() Method { 49 | var data struct{} 50 | return cm.New[Method](1, data) 51 | } 52 | 53 | // Head returns true if [Method] represents the variant case "head". 54 | func (self *Method) Head() bool { 55 | return self.Tag() == 1 56 | } 57 | 58 | // MethodPost returns a [Method] of case "post". 59 | func MethodPost() Method { 60 | var data struct{} 61 | return cm.New[Method](2, data) 62 | } 63 | 64 | // Post returns true if [Method] represents the variant case "post". 65 | func (self *Method) Post() bool { 66 | return self.Tag() == 2 67 | } 68 | 69 | // MethodPut returns a [Method] of case "put". 70 | func MethodPut() Method { 71 | var data struct{} 72 | return cm.New[Method](3, data) 73 | } 74 | 75 | // Put returns true if [Method] represents the variant case "put". 76 | func (self *Method) Put() bool { 77 | return self.Tag() == 3 78 | } 79 | 80 | // MethodDelete returns a [Method] of case "delete". 81 | func MethodDelete() Method { 82 | var data struct{} 83 | return cm.New[Method](4, data) 84 | } 85 | 86 | // Delete returns true if [Method] represents the variant case "delete". 87 | func (self *Method) Delete() bool { 88 | return self.Tag() == 4 89 | } 90 | 91 | // MethodConnect returns a [Method] of case "connect". 92 | func MethodConnect() Method { 93 | var data struct{} 94 | return cm.New[Method](5, data) 95 | } 96 | 97 | // Connect returns true if [Method] represents the variant case "connect". 98 | func (self *Method) Connect() bool { 99 | return self.Tag() == 5 100 | } 101 | 102 | // MethodOptions returns a [Method] of case "options". 103 | func MethodOptions() Method { 104 | var data struct{} 105 | return cm.New[Method](6, data) 106 | } 107 | 108 | // Options returns true if [Method] represents the variant case "options". 109 | func (self *Method) Options() bool { 110 | return self.Tag() == 6 111 | } 112 | 113 | // MethodTrace returns a [Method] of case "trace". 114 | func MethodTrace() Method { 115 | var data struct{} 116 | return cm.New[Method](7, data) 117 | } 118 | 119 | // Trace returns true if [Method] represents the variant case "trace". 120 | func (self *Method) Trace() bool { 121 | return self.Tag() == 7 122 | } 123 | 124 | // MethodPatch returns a [Method] of case "patch". 125 | func MethodPatch() Method { 126 | var data struct{} 127 | return cm.New[Method](8, data) 128 | } 129 | 130 | // Patch returns true if [Method] represents the variant case "patch". 131 | func (self *Method) Patch() bool { 132 | return self.Tag() == 8 133 | } 134 | 135 | // MethodOther returns a [Method] of case "other". 136 | func MethodOther(data string) Method { 137 | return cm.New[Method](9, data) 138 | } 139 | 140 | // Other returns a non-nil *[string] if [Method] represents the variant case "other". 141 | func (self *Method) Other() *string { 142 | return cm.Case[string](self, 9) 143 | } 144 | 145 | // Scheme represents the variant "wasi:http/types@0.2.0#scheme". 146 | // 147 | // This type corresponds to HTTP standard Related Schemes. 148 | // 149 | // variant scheme { 150 | // HTTP, 151 | // HTTPS, 152 | // other(string), 153 | // } 154 | type Scheme cm.Variant[uint8, string, string] 155 | 156 | // SchemeHTTP returns a [Scheme] of case "HTTP". 157 | func SchemeHTTP() Scheme { 158 | var data struct{} 159 | return cm.New[Scheme](0, data) 160 | } 161 | 162 | // HTTP returns true if [Scheme] represents the variant case "HTTP". 163 | func (self *Scheme) HTTP() bool { 164 | return self.Tag() == 0 165 | } 166 | 167 | // SchemeHTTPS returns a [Scheme] of case "HTTPS". 168 | func SchemeHTTPS() Scheme { 169 | var data struct{} 170 | return cm.New[Scheme](1, data) 171 | } 172 | 173 | // HTTPS returns true if [Scheme] represents the variant case "HTTPS". 174 | func (self *Scheme) HTTPS() bool { 175 | return self.Tag() == 1 176 | } 177 | 178 | // SchemeOther returns a [Scheme] of case "other". 179 | func SchemeOther(data string) Scheme { 180 | return cm.New[Scheme](2, data) 181 | } 182 | 183 | // Other returns a non-nil *[string] if [Scheme] represents the variant case "other". 184 | func (self *Scheme) Other() *string { 185 | return cm.Case[string](self, 2) 186 | } 187 | 188 | // DNSErrorPayload represents the record "wasi:http/types@0.2.0#DNS-error-payload". 189 | // 190 | // Defines the case payload type for `DNS-error` above: 191 | // 192 | // record DNS-error-payload { 193 | // rcode: option, 194 | // info-code: option, 195 | // } 196 | type DNSErrorPayload struct { 197 | Rcode cm.Option[string] 198 | InfoCode cm.Option[uint16] 199 | } 200 | 201 | // TLSAlertReceivedPayload represents the record "wasi:http/types@0.2.0#TLS-alert-received-payload". 202 | // 203 | // Defines the case payload type for `TLS-alert-received` above: 204 | // 205 | // record TLS-alert-received-payload { 206 | // alert-id: option, 207 | // alert-message: option, 208 | // } 209 | type TLSAlertReceivedPayload struct { 210 | AlertID cm.Option[uint8] 211 | AlertMessage cm.Option[string] 212 | } 213 | 214 | // FieldSizePayload represents the record "wasi:http/types@0.2.0#field-size-payload". 215 | // 216 | // Defines the case payload type for `HTTP-response-{header,trailer}-size` above: 217 | // 218 | // record field-size-payload { 219 | // field-name: option, 220 | // field-size: option, 221 | // } 222 | type FieldSizePayload struct { 223 | FieldName cm.Option[string] 224 | FieldSize cm.Option[uint32] 225 | } 226 | 227 | // ErrorCode represents the variant "wasi:http/types@0.2.0#error-code". 228 | // 229 | // These cases are inspired by the IANA HTTP Proxy Error Types: 230 | // https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types 231 | // 232 | // variant error-code { 233 | // DNS-timeout, 234 | // DNS-error(DNS-error-payload), 235 | // destination-not-found, 236 | // destination-unavailable, 237 | // destination-IP-prohibited, 238 | // destination-IP-unroutable, 239 | // connection-refused, 240 | // connection-terminated, 241 | // connection-timeout, 242 | // connection-read-timeout, 243 | // connection-write-timeout, 244 | // connection-limit-reached, 245 | // TLS-protocol-error, 246 | // TLS-certificate-error, 247 | // TLS-alert-received(TLS-alert-received-payload), 248 | // HTTP-request-denied, 249 | // HTTP-request-length-required, 250 | // HTTP-request-body-size(option), 251 | // HTTP-request-method-invalid, 252 | // HTTP-request-URI-invalid, 253 | // HTTP-request-URI-too-long, 254 | // HTTP-request-header-section-size(option), 255 | // HTTP-request-header-size(option), 256 | // HTTP-request-trailer-section-size(option), 257 | // HTTP-request-trailer-size(field-size-payload), 258 | // HTTP-response-incomplete, 259 | // HTTP-response-header-section-size(option), 260 | // HTTP-response-header-size(field-size-payload), 261 | // HTTP-response-body-size(option), 262 | // HTTP-response-trailer-section-size(option), 263 | // HTTP-response-trailer-size(field-size-payload), 264 | // HTTP-response-transfer-coding(option), 265 | // HTTP-response-content-coding(option), 266 | // HTTP-response-timeout, 267 | // HTTP-upgrade-failed, 268 | // HTTP-protocol-error, 269 | // loop-detected, 270 | // configuration-error, 271 | // internal-error(option), 272 | // } 273 | type ErrorCode cm.Variant[uint8, OptionFieldSizePayloadShape, cm.Option[uint64]] 274 | 275 | // ErrorCodeDNSTimeout returns a [ErrorCode] of case "DNS-timeout". 276 | func ErrorCodeDNSTimeout() ErrorCode { 277 | var data struct{} 278 | return cm.New[ErrorCode](0, data) 279 | } 280 | 281 | // DNSTimeout returns true if [ErrorCode] represents the variant case "DNS-timeout". 282 | func (self *ErrorCode) DNSTimeout() bool { 283 | return self.Tag() == 0 284 | } 285 | 286 | // ErrorCodeDNSError returns a [ErrorCode] of case "DNS-error". 287 | func ErrorCodeDNSError(data DNSErrorPayload) ErrorCode { 288 | return cm.New[ErrorCode](1, data) 289 | } 290 | 291 | // DNSError returns a non-nil *[DNSErrorPayload] if [ErrorCode] represents the variant case "DNS-error". 292 | func (self *ErrorCode) DNSError() *DNSErrorPayload { 293 | return cm.Case[DNSErrorPayload](self, 1) 294 | } 295 | 296 | // ErrorCodeDestinationNotFound returns a [ErrorCode] of case "destination-not-found". 297 | func ErrorCodeDestinationNotFound() ErrorCode { 298 | var data struct{} 299 | return cm.New[ErrorCode](2, data) 300 | } 301 | 302 | // DestinationNotFound returns true if [ErrorCode] represents the variant case "destination-not-found". 303 | func (self *ErrorCode) DestinationNotFound() bool { 304 | return self.Tag() == 2 305 | } 306 | 307 | // ErrorCodeDestinationUnavailable returns a [ErrorCode] of case "destination-unavailable". 308 | func ErrorCodeDestinationUnavailable() ErrorCode { 309 | var data struct{} 310 | return cm.New[ErrorCode](3, data) 311 | } 312 | 313 | // DestinationUnavailable returns true if [ErrorCode] represents the variant case "destination-unavailable". 314 | func (self *ErrorCode) DestinationUnavailable() bool { 315 | return self.Tag() == 3 316 | } 317 | 318 | // ErrorCodeDestinationIPProhibited returns a [ErrorCode] of case "destination-IP-prohibited". 319 | func ErrorCodeDestinationIPProhibited() ErrorCode { 320 | var data struct{} 321 | return cm.New[ErrorCode](4, data) 322 | } 323 | 324 | // DestinationIPProhibited returns true if [ErrorCode] represents the variant case "destination-IP-prohibited". 325 | func (self *ErrorCode) DestinationIPProhibited() bool { 326 | return self.Tag() == 4 327 | } 328 | 329 | // ErrorCodeDestinationIPUnroutable returns a [ErrorCode] of case "destination-IP-unroutable". 330 | func ErrorCodeDestinationIPUnroutable() ErrorCode { 331 | var data struct{} 332 | return cm.New[ErrorCode](5, data) 333 | } 334 | 335 | // DestinationIPUnroutable returns true if [ErrorCode] represents the variant case "destination-IP-unroutable". 336 | func (self *ErrorCode) DestinationIPUnroutable() bool { 337 | return self.Tag() == 5 338 | } 339 | 340 | // ErrorCodeConnectionRefused returns a [ErrorCode] of case "connection-refused". 341 | func ErrorCodeConnectionRefused() ErrorCode { 342 | var data struct{} 343 | return cm.New[ErrorCode](6, data) 344 | } 345 | 346 | // ConnectionRefused returns true if [ErrorCode] represents the variant case "connection-refused". 347 | func (self *ErrorCode) ConnectionRefused() bool { 348 | return self.Tag() == 6 349 | } 350 | 351 | // ErrorCodeConnectionTerminated returns a [ErrorCode] of case "connection-terminated". 352 | func ErrorCodeConnectionTerminated() ErrorCode { 353 | var data struct{} 354 | return cm.New[ErrorCode](7, data) 355 | } 356 | 357 | // ConnectionTerminated returns true if [ErrorCode] represents the variant case "connection-terminated". 358 | func (self *ErrorCode) ConnectionTerminated() bool { 359 | return self.Tag() == 7 360 | } 361 | 362 | // ErrorCodeConnectionTimeout returns a [ErrorCode] of case "connection-timeout". 363 | func ErrorCodeConnectionTimeout() ErrorCode { 364 | var data struct{} 365 | return cm.New[ErrorCode](8, data) 366 | } 367 | 368 | // ConnectionTimeout returns true if [ErrorCode] represents the variant case "connection-timeout". 369 | func (self *ErrorCode) ConnectionTimeout() bool { 370 | return self.Tag() == 8 371 | } 372 | 373 | // ErrorCodeConnectionReadTimeout returns a [ErrorCode] of case "connection-read-timeout". 374 | func ErrorCodeConnectionReadTimeout() ErrorCode { 375 | var data struct{} 376 | return cm.New[ErrorCode](9, data) 377 | } 378 | 379 | // ConnectionReadTimeout returns true if [ErrorCode] represents the variant case "connection-read-timeout". 380 | func (self *ErrorCode) ConnectionReadTimeout() bool { 381 | return self.Tag() == 9 382 | } 383 | 384 | // ErrorCodeConnectionWriteTimeout returns a [ErrorCode] of case "connection-write-timeout". 385 | func ErrorCodeConnectionWriteTimeout() ErrorCode { 386 | var data struct{} 387 | return cm.New[ErrorCode](10, data) 388 | } 389 | 390 | // ConnectionWriteTimeout returns true if [ErrorCode] represents the variant case "connection-write-timeout". 391 | func (self *ErrorCode) ConnectionWriteTimeout() bool { 392 | return self.Tag() == 10 393 | } 394 | 395 | // ErrorCodeConnectionLimitReached returns a [ErrorCode] of case "connection-limit-reached". 396 | func ErrorCodeConnectionLimitReached() ErrorCode { 397 | var data struct{} 398 | return cm.New[ErrorCode](11, data) 399 | } 400 | 401 | // ConnectionLimitReached returns true if [ErrorCode] represents the variant case "connection-limit-reached". 402 | func (self *ErrorCode) ConnectionLimitReached() bool { 403 | return self.Tag() == 11 404 | } 405 | 406 | // ErrorCodeTLSProtocolError returns a [ErrorCode] of case "TLS-protocol-error". 407 | func ErrorCodeTLSProtocolError() ErrorCode { 408 | var data struct{} 409 | return cm.New[ErrorCode](12, data) 410 | } 411 | 412 | // TLSProtocolError returns true if [ErrorCode] represents the variant case "TLS-protocol-error". 413 | func (self *ErrorCode) TLSProtocolError() bool { 414 | return self.Tag() == 12 415 | } 416 | 417 | // ErrorCodeTLSCertificateError returns a [ErrorCode] of case "TLS-certificate-error". 418 | func ErrorCodeTLSCertificateError() ErrorCode { 419 | var data struct{} 420 | return cm.New[ErrorCode](13, data) 421 | } 422 | 423 | // TLSCertificateError returns true if [ErrorCode] represents the variant case "TLS-certificate-error". 424 | func (self *ErrorCode) TLSCertificateError() bool { 425 | return self.Tag() == 13 426 | } 427 | 428 | // ErrorCodeTLSAlertReceived returns a [ErrorCode] of case "TLS-alert-received". 429 | func ErrorCodeTLSAlertReceived(data TLSAlertReceivedPayload) ErrorCode { 430 | return cm.New[ErrorCode](14, data) 431 | } 432 | 433 | // TLSAlertReceived returns a non-nil *[TLSAlertReceivedPayload] if [ErrorCode] represents the variant case "TLS-alert-received". 434 | func (self *ErrorCode) TLSAlertReceived() *TLSAlertReceivedPayload { 435 | return cm.Case[TLSAlertReceivedPayload](self, 14) 436 | } 437 | 438 | // ErrorCodeHTTPRequestDenied returns a [ErrorCode] of case "HTTP-request-denied". 439 | func ErrorCodeHTTPRequestDenied() ErrorCode { 440 | var data struct{} 441 | return cm.New[ErrorCode](15, data) 442 | } 443 | 444 | // HTTPRequestDenied returns true if [ErrorCode] represents the variant case "HTTP-request-denied". 445 | func (self *ErrorCode) HTTPRequestDenied() bool { 446 | return self.Tag() == 15 447 | } 448 | 449 | // ErrorCodeHTTPRequestLengthRequired returns a [ErrorCode] of case "HTTP-request-length-required". 450 | func ErrorCodeHTTPRequestLengthRequired() ErrorCode { 451 | var data struct{} 452 | return cm.New[ErrorCode](16, data) 453 | } 454 | 455 | // HTTPRequestLengthRequired returns true if [ErrorCode] represents the variant case "HTTP-request-length-required". 456 | func (self *ErrorCode) HTTPRequestLengthRequired() bool { 457 | return self.Tag() == 16 458 | } 459 | 460 | // ErrorCodeHTTPRequestBodySize returns a [ErrorCode] of case "HTTP-request-body-size". 461 | func ErrorCodeHTTPRequestBodySize(data cm.Option[uint64]) ErrorCode { 462 | return cm.New[ErrorCode](17, data) 463 | } 464 | 465 | // HTTPRequestBodySize returns a non-nil *[cm.Option[uint64]] if [ErrorCode] represents the variant case "HTTP-request-body-size". 466 | func (self *ErrorCode) HTTPRequestBodySize() *cm.Option[uint64] { 467 | return cm.Case[cm.Option[uint64]](self, 17) 468 | } 469 | 470 | // ErrorCodeHTTPRequestMethodInvalid returns a [ErrorCode] of case "HTTP-request-method-invalid". 471 | func ErrorCodeHTTPRequestMethodInvalid() ErrorCode { 472 | var data struct{} 473 | return cm.New[ErrorCode](18, data) 474 | } 475 | 476 | // HTTPRequestMethodInvalid returns true if [ErrorCode] represents the variant case "HTTP-request-method-invalid". 477 | func (self *ErrorCode) HTTPRequestMethodInvalid() bool { 478 | return self.Tag() == 18 479 | } 480 | 481 | // ErrorCodeHTTPRequestURIInvalid returns a [ErrorCode] of case "HTTP-request-URI-invalid". 482 | func ErrorCodeHTTPRequestURIInvalid() ErrorCode { 483 | var data struct{} 484 | return cm.New[ErrorCode](19, data) 485 | } 486 | 487 | // HTTPRequestURIInvalid returns true if [ErrorCode] represents the variant case "HTTP-request-URI-invalid". 488 | func (self *ErrorCode) HTTPRequestURIInvalid() bool { 489 | return self.Tag() == 19 490 | } 491 | 492 | // ErrorCodeHTTPRequestURITooLong returns a [ErrorCode] of case "HTTP-request-URI-too-long". 493 | func ErrorCodeHTTPRequestURITooLong() ErrorCode { 494 | var data struct{} 495 | return cm.New[ErrorCode](20, data) 496 | } 497 | 498 | // HTTPRequestURITooLong returns true if [ErrorCode] represents the variant case "HTTP-request-URI-too-long". 499 | func (self *ErrorCode) HTTPRequestURITooLong() bool { 500 | return self.Tag() == 20 501 | } 502 | 503 | // ErrorCodeHTTPRequestHeaderSectionSize returns a [ErrorCode] of case "HTTP-request-header-section-size". 504 | func ErrorCodeHTTPRequestHeaderSectionSize(data cm.Option[uint32]) ErrorCode { 505 | return cm.New[ErrorCode](21, data) 506 | } 507 | 508 | // HTTPRequestHeaderSectionSize returns a non-nil *[cm.Option[uint32]] if [ErrorCode] represents the variant case "HTTP-request-header-section-size". 509 | func (self *ErrorCode) HTTPRequestHeaderSectionSize() *cm.Option[uint32] { 510 | return cm.Case[cm.Option[uint32]](self, 21) 511 | } 512 | 513 | // ErrorCodeHTTPRequestHeaderSize returns a [ErrorCode] of case "HTTP-request-header-size". 514 | func ErrorCodeHTTPRequestHeaderSize(data cm.Option[FieldSizePayload]) ErrorCode { 515 | return cm.New[ErrorCode](22, data) 516 | } 517 | 518 | // HTTPRequestHeaderSize returns a non-nil *[cm.Option[FieldSizePayload]] if [ErrorCode] represents the variant case "HTTP-request-header-size". 519 | func (self *ErrorCode) HTTPRequestHeaderSize() *cm.Option[FieldSizePayload] { 520 | return cm.Case[cm.Option[FieldSizePayload]](self, 22) 521 | } 522 | 523 | // ErrorCodeHTTPRequestTrailerSectionSize returns a [ErrorCode] of case "HTTP-request-trailer-section-size". 524 | func ErrorCodeHTTPRequestTrailerSectionSize(data cm.Option[uint32]) ErrorCode { 525 | return cm.New[ErrorCode](23, data) 526 | } 527 | 528 | // HTTPRequestTrailerSectionSize returns a non-nil *[cm.Option[uint32]] if [ErrorCode] represents the variant case "HTTP-request-trailer-section-size". 529 | func (self *ErrorCode) HTTPRequestTrailerSectionSize() *cm.Option[uint32] { 530 | return cm.Case[cm.Option[uint32]](self, 23) 531 | } 532 | 533 | // ErrorCodeHTTPRequestTrailerSize returns a [ErrorCode] of case "HTTP-request-trailer-size". 534 | func ErrorCodeHTTPRequestTrailerSize(data FieldSizePayload) ErrorCode { 535 | return cm.New[ErrorCode](24, data) 536 | } 537 | 538 | // HTTPRequestTrailerSize returns a non-nil *[FieldSizePayload] if [ErrorCode] represents the variant case "HTTP-request-trailer-size". 539 | func (self *ErrorCode) HTTPRequestTrailerSize() *FieldSizePayload { 540 | return cm.Case[FieldSizePayload](self, 24) 541 | } 542 | 543 | // ErrorCodeHTTPResponseIncomplete returns a [ErrorCode] of case "HTTP-response-incomplete". 544 | func ErrorCodeHTTPResponseIncomplete() ErrorCode { 545 | var data struct{} 546 | return cm.New[ErrorCode](25, data) 547 | } 548 | 549 | // HTTPResponseIncomplete returns true if [ErrorCode] represents the variant case "HTTP-response-incomplete". 550 | func (self *ErrorCode) HTTPResponseIncomplete() bool { 551 | return self.Tag() == 25 552 | } 553 | 554 | // ErrorCodeHTTPResponseHeaderSectionSize returns a [ErrorCode] of case "HTTP-response-header-section-size". 555 | func ErrorCodeHTTPResponseHeaderSectionSize(data cm.Option[uint32]) ErrorCode { 556 | return cm.New[ErrorCode](26, data) 557 | } 558 | 559 | // HTTPResponseHeaderSectionSize returns a non-nil *[cm.Option[uint32]] if [ErrorCode] represents the variant case "HTTP-response-header-section-size". 560 | func (self *ErrorCode) HTTPResponseHeaderSectionSize() *cm.Option[uint32] { 561 | return cm.Case[cm.Option[uint32]](self, 26) 562 | } 563 | 564 | // ErrorCodeHTTPResponseHeaderSize returns a [ErrorCode] of case "HTTP-response-header-size". 565 | func ErrorCodeHTTPResponseHeaderSize(data FieldSizePayload) ErrorCode { 566 | return cm.New[ErrorCode](27, data) 567 | } 568 | 569 | // HTTPResponseHeaderSize returns a non-nil *[FieldSizePayload] if [ErrorCode] represents the variant case "HTTP-response-header-size". 570 | func (self *ErrorCode) HTTPResponseHeaderSize() *FieldSizePayload { 571 | return cm.Case[FieldSizePayload](self, 27) 572 | } 573 | 574 | // ErrorCodeHTTPResponseBodySize returns a [ErrorCode] of case "HTTP-response-body-size". 575 | func ErrorCodeHTTPResponseBodySize(data cm.Option[uint64]) ErrorCode { 576 | return cm.New[ErrorCode](28, data) 577 | } 578 | 579 | // HTTPResponseBodySize returns a non-nil *[cm.Option[uint64]] if [ErrorCode] represents the variant case "HTTP-response-body-size". 580 | func (self *ErrorCode) HTTPResponseBodySize() *cm.Option[uint64] { 581 | return cm.Case[cm.Option[uint64]](self, 28) 582 | } 583 | 584 | // ErrorCodeHTTPResponseTrailerSectionSize returns a [ErrorCode] of case "HTTP-response-trailer-section-size". 585 | func ErrorCodeHTTPResponseTrailerSectionSize(data cm.Option[uint32]) ErrorCode { 586 | return cm.New[ErrorCode](29, data) 587 | } 588 | 589 | // HTTPResponseTrailerSectionSize returns a non-nil *[cm.Option[uint32]] if [ErrorCode] represents the variant case "HTTP-response-trailer-section-size". 590 | func (self *ErrorCode) HTTPResponseTrailerSectionSize() *cm.Option[uint32] { 591 | return cm.Case[cm.Option[uint32]](self, 29) 592 | } 593 | 594 | // ErrorCodeHTTPResponseTrailerSize returns a [ErrorCode] of case "HTTP-response-trailer-size". 595 | func ErrorCodeHTTPResponseTrailerSize(data FieldSizePayload) ErrorCode { 596 | return cm.New[ErrorCode](30, data) 597 | } 598 | 599 | // HTTPResponseTrailerSize returns a non-nil *[FieldSizePayload] if [ErrorCode] represents the variant case "HTTP-response-trailer-size". 600 | func (self *ErrorCode) HTTPResponseTrailerSize() *FieldSizePayload { 601 | return cm.Case[FieldSizePayload](self, 30) 602 | } 603 | 604 | // ErrorCodeHTTPResponseTransferCoding returns a [ErrorCode] of case "HTTP-response-transfer-coding". 605 | func ErrorCodeHTTPResponseTransferCoding(data cm.Option[string]) ErrorCode { 606 | return cm.New[ErrorCode](31, data) 607 | } 608 | 609 | // HTTPResponseTransferCoding returns a non-nil *[cm.Option[string]] if [ErrorCode] represents the variant case "HTTP-response-transfer-coding". 610 | func (self *ErrorCode) HTTPResponseTransferCoding() *cm.Option[string] { 611 | return cm.Case[cm.Option[string]](self, 31) 612 | } 613 | 614 | // ErrorCodeHTTPResponseContentCoding returns a [ErrorCode] of case "HTTP-response-content-coding". 615 | func ErrorCodeHTTPResponseContentCoding(data cm.Option[string]) ErrorCode { 616 | return cm.New[ErrorCode](32, data) 617 | } 618 | 619 | // HTTPResponseContentCoding returns a non-nil *[cm.Option[string]] if [ErrorCode] represents the variant case "HTTP-response-content-coding". 620 | func (self *ErrorCode) HTTPResponseContentCoding() *cm.Option[string] { 621 | return cm.Case[cm.Option[string]](self, 32) 622 | } 623 | 624 | // ErrorCodeHTTPResponseTimeout returns a [ErrorCode] of case "HTTP-response-timeout". 625 | func ErrorCodeHTTPResponseTimeout() ErrorCode { 626 | var data struct{} 627 | return cm.New[ErrorCode](33, data) 628 | } 629 | 630 | // HTTPResponseTimeout returns true if [ErrorCode] represents the variant case "HTTP-response-timeout". 631 | func (self *ErrorCode) HTTPResponseTimeout() bool { 632 | return self.Tag() == 33 633 | } 634 | 635 | // ErrorCodeHTTPUpgradeFailed returns a [ErrorCode] of case "HTTP-upgrade-failed". 636 | func ErrorCodeHTTPUpgradeFailed() ErrorCode { 637 | var data struct{} 638 | return cm.New[ErrorCode](34, data) 639 | } 640 | 641 | // HTTPUpgradeFailed returns true if [ErrorCode] represents the variant case "HTTP-upgrade-failed". 642 | func (self *ErrorCode) HTTPUpgradeFailed() bool { 643 | return self.Tag() == 34 644 | } 645 | 646 | // ErrorCodeHTTPProtocolError returns a [ErrorCode] of case "HTTP-protocol-error". 647 | func ErrorCodeHTTPProtocolError() ErrorCode { 648 | var data struct{} 649 | return cm.New[ErrorCode](35, data) 650 | } 651 | 652 | // HTTPProtocolError returns true if [ErrorCode] represents the variant case "HTTP-protocol-error". 653 | func (self *ErrorCode) HTTPProtocolError() bool { 654 | return self.Tag() == 35 655 | } 656 | 657 | // ErrorCodeLoopDetected returns a [ErrorCode] of case "loop-detected". 658 | func ErrorCodeLoopDetected() ErrorCode { 659 | var data struct{} 660 | return cm.New[ErrorCode](36, data) 661 | } 662 | 663 | // LoopDetected returns true if [ErrorCode] represents the variant case "loop-detected". 664 | func (self *ErrorCode) LoopDetected() bool { 665 | return self.Tag() == 36 666 | } 667 | 668 | // ErrorCodeConfigurationError returns a [ErrorCode] of case "configuration-error". 669 | func ErrorCodeConfigurationError() ErrorCode { 670 | var data struct{} 671 | return cm.New[ErrorCode](37, data) 672 | } 673 | 674 | // ConfigurationError returns true if [ErrorCode] represents the variant case "configuration-error". 675 | func (self *ErrorCode) ConfigurationError() bool { 676 | return self.Tag() == 37 677 | } 678 | 679 | // ErrorCodeInternalError returns a [ErrorCode] of case "internal-error". 680 | // 681 | // This is a catch-all error for anything that doesn't fit cleanly into a 682 | // more specific case. It also includes an optional string for an 683 | // unstructured description of the error. Users should not depend on the 684 | // string for diagnosing errors, as it's not required to be consistent 685 | // between implementations. 686 | func ErrorCodeInternalError(data cm.Option[string]) ErrorCode { 687 | return cm.New[ErrorCode](38, data) 688 | } 689 | 690 | // InternalError returns a non-nil *[cm.Option[string]] if [ErrorCode] represents the variant case "internal-error". 691 | func (self *ErrorCode) InternalError() *cm.Option[string] { 692 | return cm.Case[cm.Option[string]](self, 38) 693 | } 694 | 695 | // HeaderError represents the variant "wasi:http/types@0.2.0#header-error". 696 | // 697 | // This type enumerates the different kinds of errors that may occur when 698 | // setting or appending to a `fields` resource. 699 | // 700 | // variant header-error { 701 | // invalid-syntax, 702 | // forbidden, 703 | // immutable, 704 | // } 705 | type HeaderError uint8 706 | 707 | const ( 708 | // This error indicates that a `field-key` or `field-value` was 709 | // syntactically invalid when used with an operation that sets headers in a 710 | // `fields`. 711 | HeaderErrorInvalidSyntax HeaderError = iota 712 | 713 | // This error indicates that a forbidden `field-key` was used when trying 714 | // to set a header in a `fields`. 715 | HeaderErrorForbidden 716 | 717 | // This error indicates that the operation on the `fields` was not 718 | // permitted because the fields are immutable. 719 | HeaderErrorImmutable 720 | ) 721 | 722 | var stringsHeaderError = [3]string{ 723 | "invalid-syntax", 724 | "forbidden", 725 | "immutable", 726 | } 727 | 728 | // String implements [fmt.Stringer], returning the enum case name of e. 729 | func (e HeaderError) String() string { 730 | return stringsHeaderError[e] 731 | } 732 | 733 | // FieldKey represents the string "wasi:http/types@0.2.0#field-key". 734 | // 735 | // Field keys are always strings. 736 | // 737 | // type field-key = string 738 | type FieldKey string 739 | 740 | // FieldValue represents the list "wasi:http/types@0.2.0#field-value". 741 | // 742 | // Field values should always be ASCII strings. However, in 743 | // reality, HTTP implementations often have to interpret malformed values, 744 | // so they are provided as a list of bytes. 745 | // 746 | // type field-value = list 747 | type FieldValue cm.List[uint8] 748 | 749 | // Fields represents the imported resource "wasi:http/types@0.2.0#fields". 750 | // 751 | // This following block defines the `fields` resource which corresponds to 752 | // HTTP standard Fields. Fields are a common representation used for both 753 | // Headers and Trailers. 754 | // 755 | // A `fields` may be mutable or immutable. A `fields` created using the 756 | // constructor, `from-list`, or `clone` will be mutable, but a `fields` 757 | // resource given by other means (including, but not limited to, 758 | // `incoming-request.headers`, `outgoing-request.headers`) might be be 759 | // immutable. In an immutable fields, the `set`, `append`, and `delete` 760 | // operations will fail with `header-error.immutable`. 761 | // 762 | // resource fields 763 | type Fields cm.Resource 764 | 765 | // ResourceDrop represents the imported resource-drop for resource "fields". 766 | // 767 | // Drops a resource handle. 768 | // 769 | //go:nosplit 770 | func (self Fields) ResourceDrop() { 771 | self0 := cm.Reinterpret[uint32](self) 772 | wasmimport_FieldsResourceDrop((uint32)(self0)) 773 | return 774 | } 775 | 776 | //go:wasmimport wasi:http/types@0.2.0 [resource-drop]fields 777 | //go:noescape 778 | func wasmimport_FieldsResourceDrop(self0 uint32) 779 | 780 | // NewFields represents the imported constructor for resource "fields". 781 | // 782 | // Construct an empty HTTP Fields. 783 | // 784 | // The resulting `fields` is mutable. 785 | // 786 | // constructor() 787 | // 788 | //go:nosplit 789 | func NewFields() (result Fields) { 790 | result0 := wasmimport_NewFields() 791 | result = cm.Reinterpret[Fields]((uint32)(result0)) 792 | return 793 | } 794 | 795 | //go:wasmimport wasi:http/types@0.2.0 [constructor]fields 796 | //go:noescape 797 | func wasmimport_NewFields() (result0 uint32) 798 | 799 | // FieldsFromList represents the imported static function "from-list". 800 | // 801 | // Construct an HTTP Fields. 802 | // 803 | // The resulting `fields` is mutable. 804 | // 805 | // The list represents each key-value pair in the Fields. Keys 806 | // which have multiple values are represented by multiple entries in this 807 | // list with the same key. 808 | // 809 | // The tuple is a pair of the field key, represented as a string, and 810 | // Value, represented as a list of bytes. In a valid Fields, all keys 811 | // and values are valid UTF-8 strings. However, values are not always 812 | // well-formed, so they are represented as a raw list of bytes. 813 | // 814 | // An error result will be returned if any header or value was 815 | // syntactically invalid, or if a header was forbidden. 816 | // 817 | // from-list: static func(entries: list>) -> result 819 | // 820 | //go:nosplit 821 | func FieldsFromList(entries cm.List[cm.Tuple[FieldKey, FieldValue]]) (result cm.Result[Fields, Fields, HeaderError]) { 822 | entries0, entries1 := cm.LowerList(entries) 823 | wasmimport_FieldsFromList((*cm.Tuple[FieldKey, FieldValue])(entries0), (uint32)(entries1), &result) 824 | return 825 | } 826 | 827 | //go:wasmimport wasi:http/types@0.2.0 [static]fields.from-list 828 | //go:noescape 829 | func wasmimport_FieldsFromList(entries0 *cm.Tuple[FieldKey, FieldValue], entries1 uint32, result *cm.Result[Fields, Fields, HeaderError]) 830 | 831 | // Append represents the imported method "append". 832 | // 833 | // Append a value for a key. Does not change or delete any existing 834 | // values for that key. 835 | // 836 | // Fails with `header-error.immutable` if the `fields` are immutable. 837 | // 838 | // append: func(name: field-key, value: field-value) -> result<_, header-error> 839 | // 840 | //go:nosplit 841 | func (self Fields) Append(name FieldKey, value FieldValue) (result cm.Result[HeaderError, struct{}, HeaderError]) { 842 | self0 := cm.Reinterpret[uint32](self) 843 | name0, name1 := cm.LowerString(name) 844 | value0, value1 := cm.LowerList(value) 845 | wasmimport_FieldsAppend((uint32)(self0), (*uint8)(name0), (uint32)(name1), (*uint8)(value0), (uint32)(value1), &result) 846 | return 847 | } 848 | 849 | //go:wasmimport wasi:http/types@0.2.0 [method]fields.append 850 | //go:noescape 851 | func wasmimport_FieldsAppend(self0 uint32, name0 *uint8, name1 uint32, value0 *uint8, value1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) 852 | 853 | // Clone represents the imported method "clone". 854 | // 855 | // Make a deep copy of the Fields. Equivelant in behavior to calling the 856 | // `fields` constructor on the return value of `entries`. The resulting 857 | // `fields` is mutable. 858 | // 859 | // clone: func() -> fields 860 | // 861 | //go:nosplit 862 | func (self Fields) Clone() (result Fields) { 863 | self0 := cm.Reinterpret[uint32](self) 864 | result0 := wasmimport_FieldsClone((uint32)(self0)) 865 | result = cm.Reinterpret[Fields]((uint32)(result0)) 866 | return 867 | } 868 | 869 | //go:wasmimport wasi:http/types@0.2.0 [method]fields.clone 870 | //go:noescape 871 | func wasmimport_FieldsClone(self0 uint32) (result0 uint32) 872 | 873 | // Delete represents the imported method "delete". 874 | // 875 | // Delete all values for a key. Does nothing if no values for the key 876 | // exist. 877 | // 878 | // Fails with `header-error.immutable` if the `fields` are immutable. 879 | // 880 | // delete: func(name: field-key) -> result<_, header-error> 881 | // 882 | //go:nosplit 883 | func (self Fields) Delete(name FieldKey) (result cm.Result[HeaderError, struct{}, HeaderError]) { 884 | self0 := cm.Reinterpret[uint32](self) 885 | name0, name1 := cm.LowerString(name) 886 | wasmimport_FieldsDelete((uint32)(self0), (*uint8)(name0), (uint32)(name1), &result) 887 | return 888 | } 889 | 890 | //go:wasmimport wasi:http/types@0.2.0 [method]fields.delete 891 | //go:noescape 892 | func wasmimport_FieldsDelete(self0 uint32, name0 *uint8, name1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) 893 | 894 | // Entries represents the imported method "entries". 895 | // 896 | // Retrieve the full set of keys and values in the Fields. Like the 897 | // constructor, the list represents each key-value pair. 898 | // 899 | // The outer list represents each key-value pair in the Fields. Keys 900 | // which have multiple values are represented by multiple entries in this 901 | // list with the same key. 902 | // 903 | // entries: func() -> list> 904 | // 905 | //go:nosplit 906 | func (self Fields) Entries() (result cm.List[cm.Tuple[FieldKey, FieldValue]]) { 907 | self0 := cm.Reinterpret[uint32](self) 908 | wasmimport_FieldsEntries((uint32)(self0), &result) 909 | return 910 | } 911 | 912 | //go:wasmimport wasi:http/types@0.2.0 [method]fields.entries 913 | //go:noescape 914 | func wasmimport_FieldsEntries(self0 uint32, result *cm.List[cm.Tuple[FieldKey, FieldValue]]) 915 | 916 | // Get represents the imported method "get". 917 | // 918 | // Get all of the values corresponding to a key. If the key is not present 919 | // in this `fields`, an empty list is returned. However, if the key is 920 | // present but empty, this is represented by a list with one or more 921 | // empty field-values present. 922 | // 923 | // get: func(name: field-key) -> list 924 | // 925 | //go:nosplit 926 | func (self Fields) Get(name FieldKey) (result cm.List[FieldValue]) { 927 | self0 := cm.Reinterpret[uint32](self) 928 | name0, name1 := cm.LowerString(name) 929 | wasmimport_FieldsGet((uint32)(self0), (*uint8)(name0), (uint32)(name1), &result) 930 | return 931 | } 932 | 933 | //go:wasmimport wasi:http/types@0.2.0 [method]fields.get 934 | //go:noescape 935 | func wasmimport_FieldsGet(self0 uint32, name0 *uint8, name1 uint32, result *cm.List[FieldValue]) 936 | 937 | // Has represents the imported method "has". 938 | // 939 | // Returns `true` when the key is present in this `fields`. If the key is 940 | // syntactically invalid, `false` is returned. 941 | // 942 | // has: func(name: field-key) -> bool 943 | // 944 | //go:nosplit 945 | func (self Fields) Has(name FieldKey) (result bool) { 946 | self0 := cm.Reinterpret[uint32](self) 947 | name0, name1 := cm.LowerString(name) 948 | result0 := wasmimport_FieldsHas((uint32)(self0), (*uint8)(name0), (uint32)(name1)) 949 | result = cm.U32ToBool((uint32)(result0)) 950 | return 951 | } 952 | 953 | //go:wasmimport wasi:http/types@0.2.0 [method]fields.has 954 | //go:noescape 955 | func wasmimport_FieldsHas(self0 uint32, name0 *uint8, name1 uint32) (result0 uint32) 956 | 957 | // Set represents the imported method "set". 958 | // 959 | // Set all of the values for a key. Clears any existing values for that 960 | // key, if they have been set. 961 | // 962 | // Fails with `header-error.immutable` if the `fields` are immutable. 963 | // 964 | // set: func(name: field-key, value: list) -> result<_, header-error> 965 | // 966 | //go:nosplit 967 | func (self Fields) Set(name FieldKey, value cm.List[FieldValue]) (result cm.Result[HeaderError, struct{}, HeaderError]) { 968 | self0 := cm.Reinterpret[uint32](self) 969 | name0, name1 := cm.LowerString(name) 970 | value0, value1 := cm.LowerList(value) 971 | wasmimport_FieldsSet((uint32)(self0), (*uint8)(name0), (uint32)(name1), (*FieldValue)(value0), (uint32)(value1), &result) 972 | return 973 | } 974 | 975 | //go:wasmimport wasi:http/types@0.2.0 [method]fields.set 976 | //go:noescape 977 | func wasmimport_FieldsSet(self0 uint32, name0 *uint8, name1 uint32, value0 *FieldValue, value1 uint32, result *cm.Result[HeaderError, struct{}, HeaderError]) 978 | 979 | // IncomingRequest represents the imported resource "wasi:http/types@0.2.0#incoming-request". 980 | // 981 | // Represents an incoming HTTP Request. 982 | // 983 | // resource incoming-request 984 | type IncomingRequest cm.Resource 985 | 986 | // ResourceDrop represents the imported resource-drop for resource "incoming-request". 987 | // 988 | // Drops a resource handle. 989 | // 990 | //go:nosplit 991 | func (self IncomingRequest) ResourceDrop() { 992 | self0 := cm.Reinterpret[uint32](self) 993 | wasmimport_IncomingRequestResourceDrop((uint32)(self0)) 994 | return 995 | } 996 | 997 | //go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-request 998 | //go:noescape 999 | func wasmimport_IncomingRequestResourceDrop(self0 uint32) 1000 | 1001 | // Authority represents the imported method "authority". 1002 | // 1003 | // Returns the authority from the request, if it was present. 1004 | // 1005 | // authority: func() -> option 1006 | // 1007 | //go:nosplit 1008 | func (self IncomingRequest) Authority() (result cm.Option[string]) { 1009 | self0 := cm.Reinterpret[uint32](self) 1010 | wasmimport_IncomingRequestAuthority((uint32)(self0), &result) 1011 | return 1012 | } 1013 | 1014 | //go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.authority 1015 | //go:noescape 1016 | func wasmimport_IncomingRequestAuthority(self0 uint32, result *cm.Option[string]) 1017 | 1018 | // Consume represents the imported method "consume". 1019 | // 1020 | // Gives the `incoming-body` associated with this request. Will only 1021 | // return success at most once, and subsequent calls will return error. 1022 | // 1023 | // consume: func() -> result 1024 | // 1025 | //go:nosplit 1026 | func (self IncomingRequest) Consume() (result cm.Result[IncomingBody, IncomingBody, struct{}]) { 1027 | self0 := cm.Reinterpret[uint32](self) 1028 | wasmimport_IncomingRequestConsume((uint32)(self0), &result) 1029 | return 1030 | } 1031 | 1032 | //go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.consume 1033 | //go:noescape 1034 | func wasmimport_IncomingRequestConsume(self0 uint32, result *cm.Result[IncomingBody, IncomingBody, struct{}]) 1035 | 1036 | // Headers represents the imported method "headers". 1037 | // 1038 | // Get the `headers` associated with the request. 1039 | // 1040 | // The returned `headers` resource is immutable: `set`, `append`, and 1041 | // `delete` operations will fail with `header-error.immutable`. 1042 | // 1043 | // The `headers` returned are a child resource: it must be dropped before 1044 | // the parent `incoming-request` is dropped. Dropping this 1045 | // `incoming-request` before all children are dropped will trap. 1046 | // 1047 | // headers: func() -> headers 1048 | // 1049 | //go:nosplit 1050 | func (self IncomingRequest) Headers() (result Fields) { 1051 | self0 := cm.Reinterpret[uint32](self) 1052 | result0 := wasmimport_IncomingRequestHeaders((uint32)(self0)) 1053 | result = cm.Reinterpret[Fields]((uint32)(result0)) 1054 | return 1055 | } 1056 | 1057 | //go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.headers 1058 | //go:noescape 1059 | func wasmimport_IncomingRequestHeaders(self0 uint32) (result0 uint32) 1060 | 1061 | // Method represents the imported method "method". 1062 | // 1063 | // Returns the method of the incoming request. 1064 | // 1065 | // method: func() -> method 1066 | // 1067 | //go:nosplit 1068 | func (self IncomingRequest) Method() (result Method) { 1069 | self0 := cm.Reinterpret[uint32](self) 1070 | wasmimport_IncomingRequestMethod((uint32)(self0), &result) 1071 | return 1072 | } 1073 | 1074 | //go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.method 1075 | //go:noescape 1076 | func wasmimport_IncomingRequestMethod(self0 uint32, result *Method) 1077 | 1078 | // PathWithQuery represents the imported method "path-with-query". 1079 | // 1080 | // Returns the path with query parameters from the request, as a string. 1081 | // 1082 | // path-with-query: func() -> option 1083 | // 1084 | //go:nosplit 1085 | func (self IncomingRequest) PathWithQuery() (result cm.Option[string]) { 1086 | self0 := cm.Reinterpret[uint32](self) 1087 | wasmimport_IncomingRequestPathWithQuery((uint32)(self0), &result) 1088 | return 1089 | } 1090 | 1091 | //go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.path-with-query 1092 | //go:noescape 1093 | func wasmimport_IncomingRequestPathWithQuery(self0 uint32, result *cm.Option[string]) 1094 | 1095 | // Scheme represents the imported method "scheme". 1096 | // 1097 | // Returns the protocol scheme from the request. 1098 | // 1099 | // scheme: func() -> option 1100 | // 1101 | //go:nosplit 1102 | func (self IncomingRequest) Scheme() (result cm.Option[Scheme]) { 1103 | self0 := cm.Reinterpret[uint32](self) 1104 | wasmimport_IncomingRequestScheme((uint32)(self0), &result) 1105 | return 1106 | } 1107 | 1108 | //go:wasmimport wasi:http/types@0.2.0 [method]incoming-request.scheme 1109 | //go:noescape 1110 | func wasmimport_IncomingRequestScheme(self0 uint32, result *cm.Option[Scheme]) 1111 | 1112 | // OutgoingRequest represents the imported resource "wasi:http/types@0.2.0#outgoing-request". 1113 | // 1114 | // Represents an outgoing HTTP Request. 1115 | // 1116 | // resource outgoing-request 1117 | type OutgoingRequest cm.Resource 1118 | 1119 | // ResourceDrop represents the imported resource-drop for resource "outgoing-request". 1120 | // 1121 | // Drops a resource handle. 1122 | // 1123 | //go:nosplit 1124 | func (self OutgoingRequest) ResourceDrop() { 1125 | self0 := cm.Reinterpret[uint32](self) 1126 | wasmimport_OutgoingRequestResourceDrop((uint32)(self0)) 1127 | return 1128 | } 1129 | 1130 | //go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-request 1131 | //go:noescape 1132 | func wasmimport_OutgoingRequestResourceDrop(self0 uint32) 1133 | 1134 | // NewOutgoingRequest represents the imported constructor for resource "outgoing-request". 1135 | // 1136 | // Construct a new `outgoing-request` with a default `method` of `GET`, and 1137 | // `none` values for `path-with-query`, `scheme`, and `authority`. 1138 | // 1139 | // * `headers` is the HTTP Headers for the Request. 1140 | // 1141 | // It is possible to construct, or manipulate with the accessor functions 1142 | // below, an `outgoing-request` with an invalid combination of `scheme` 1143 | // and `authority`, or `headers` which are not permitted to be sent. 1144 | // It is the obligation of the `outgoing-handler.handle` implementation 1145 | // to reject invalid constructions of `outgoing-request`. 1146 | // 1147 | // constructor(headers: headers) 1148 | // 1149 | //go:nosplit 1150 | func NewOutgoingRequest(headers Fields) (result OutgoingRequest) { 1151 | headers0 := cm.Reinterpret[uint32](headers) 1152 | result0 := wasmimport_NewOutgoingRequest((uint32)(headers0)) 1153 | result = cm.Reinterpret[OutgoingRequest]((uint32)(result0)) 1154 | return 1155 | } 1156 | 1157 | //go:wasmimport wasi:http/types@0.2.0 [constructor]outgoing-request 1158 | //go:noescape 1159 | func wasmimport_NewOutgoingRequest(headers0 uint32) (result0 uint32) 1160 | 1161 | // Authority represents the imported method "authority". 1162 | // 1163 | // Get the HTTP Authority for the Request. A value of `none` may be used 1164 | // with Related Schemes which do not require an Authority. The HTTP and 1165 | // HTTPS schemes always require an authority. 1166 | // 1167 | // authority: func() -> option 1168 | // 1169 | //go:nosplit 1170 | func (self OutgoingRequest) Authority() (result cm.Option[string]) { 1171 | self0 := cm.Reinterpret[uint32](self) 1172 | wasmimport_OutgoingRequestAuthority((uint32)(self0), &result) 1173 | return 1174 | } 1175 | 1176 | //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.authority 1177 | //go:noescape 1178 | func wasmimport_OutgoingRequestAuthority(self0 uint32, result *cm.Option[string]) 1179 | 1180 | // Body represents the imported method "body". 1181 | // 1182 | // Returns the resource corresponding to the outgoing Body for this 1183 | // Request. 1184 | // 1185 | // Returns success on the first call: the `outgoing-body` resource for 1186 | // this `outgoing-request` can be retrieved at most once. Subsequent 1187 | // calls will return error. 1188 | // 1189 | // body: func() -> result 1190 | // 1191 | //go:nosplit 1192 | func (self OutgoingRequest) Body() (result cm.Result[OutgoingBody, OutgoingBody, struct{}]) { 1193 | self0 := cm.Reinterpret[uint32](self) 1194 | wasmimport_OutgoingRequestBody((uint32)(self0), &result) 1195 | return 1196 | } 1197 | 1198 | //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.body 1199 | //go:noescape 1200 | func wasmimport_OutgoingRequestBody(self0 uint32, result *cm.Result[OutgoingBody, OutgoingBody, struct{}]) 1201 | 1202 | // Headers represents the imported method "headers". 1203 | // 1204 | // Get the headers associated with the Request. 1205 | // 1206 | // The returned `headers` resource is immutable: `set`, `append`, and 1207 | // `delete` operations will fail with `header-error.immutable`. 1208 | // 1209 | // This headers resource is a child: it must be dropped before the parent 1210 | // `outgoing-request` is dropped, or its ownership is transfered to 1211 | // another component by e.g. `outgoing-handler.handle`. 1212 | // 1213 | // headers: func() -> headers 1214 | // 1215 | //go:nosplit 1216 | func (self OutgoingRequest) Headers() (result Fields) { 1217 | self0 := cm.Reinterpret[uint32](self) 1218 | result0 := wasmimport_OutgoingRequestHeaders((uint32)(self0)) 1219 | result = cm.Reinterpret[Fields]((uint32)(result0)) 1220 | return 1221 | } 1222 | 1223 | //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.headers 1224 | //go:noescape 1225 | func wasmimport_OutgoingRequestHeaders(self0 uint32) (result0 uint32) 1226 | 1227 | // Method represents the imported method "method". 1228 | // 1229 | // Get the Method for the Request. 1230 | // 1231 | // method: func() -> method 1232 | // 1233 | //go:nosplit 1234 | func (self OutgoingRequest) Method() (result Method) { 1235 | self0 := cm.Reinterpret[uint32](self) 1236 | wasmimport_OutgoingRequestMethod((uint32)(self0), &result) 1237 | return 1238 | } 1239 | 1240 | //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.method 1241 | //go:noescape 1242 | func wasmimport_OutgoingRequestMethod(self0 uint32, result *Method) 1243 | 1244 | // PathWithQuery represents the imported method "path-with-query". 1245 | // 1246 | // Get the combination of the HTTP Path and Query for the Request. 1247 | // When `none`, this represents an empty Path and empty Query. 1248 | // 1249 | // path-with-query: func() -> option 1250 | // 1251 | //go:nosplit 1252 | func (self OutgoingRequest) PathWithQuery() (result cm.Option[string]) { 1253 | self0 := cm.Reinterpret[uint32](self) 1254 | wasmimport_OutgoingRequestPathWithQuery((uint32)(self0), &result) 1255 | return 1256 | } 1257 | 1258 | //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.path-with-query 1259 | //go:noescape 1260 | func wasmimport_OutgoingRequestPathWithQuery(self0 uint32, result *cm.Option[string]) 1261 | 1262 | // Scheme represents the imported method "scheme". 1263 | // 1264 | // Get the HTTP Related Scheme for the Request. When `none`, the 1265 | // implementation may choose an appropriate default scheme. 1266 | // 1267 | // scheme: func() -> option 1268 | // 1269 | //go:nosplit 1270 | func (self OutgoingRequest) Scheme() (result cm.Option[Scheme]) { 1271 | self0 := cm.Reinterpret[uint32](self) 1272 | wasmimport_OutgoingRequestScheme((uint32)(self0), &result) 1273 | return 1274 | } 1275 | 1276 | //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.scheme 1277 | //go:noescape 1278 | func wasmimport_OutgoingRequestScheme(self0 uint32, result *cm.Option[Scheme]) 1279 | 1280 | // SetAuthority represents the imported method "set-authority". 1281 | // 1282 | // Set the HTTP Authority for the Request. A value of `none` may be used 1283 | // with Related Schemes which do not require an Authority. The HTTP and 1284 | // HTTPS schemes always require an authority. Fails if the string given is 1285 | // not a syntactically valid uri authority. 1286 | // 1287 | // set-authority: func(authority: option) -> result 1288 | // 1289 | //go:nosplit 1290 | func (self OutgoingRequest) SetAuthority(authority cm.Option[string]) (result cm.BoolResult) { 1291 | self0 := cm.Reinterpret[uint32](self) 1292 | authority0, authority1, authority2 := lower_OptionString(authority) 1293 | result0 := wasmimport_OutgoingRequestSetAuthority((uint32)(self0), (uint32)(authority0), (*uint8)(authority1), (uint32)(authority2)) 1294 | result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) 1295 | return 1296 | } 1297 | 1298 | //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-authority 1299 | //go:noescape 1300 | func wasmimport_OutgoingRequestSetAuthority(self0 uint32, authority0 uint32, authority1 *uint8, authority2 uint32) (result0 uint32) 1301 | 1302 | // SetMethod represents the imported method "set-method". 1303 | // 1304 | // Set the Method for the Request. Fails if the string present in a 1305 | // `method.other` argument is not a syntactically valid method. 1306 | // 1307 | // set-method: func(method: method) -> result 1308 | // 1309 | //go:nosplit 1310 | func (self OutgoingRequest) SetMethod(method Method) (result cm.BoolResult) { 1311 | self0 := cm.Reinterpret[uint32](self) 1312 | method0, method1, method2 := lower_Method(method) 1313 | result0 := wasmimport_OutgoingRequestSetMethod((uint32)(self0), (uint32)(method0), (*uint8)(method1), (uint32)(method2)) 1314 | result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) 1315 | return 1316 | } 1317 | 1318 | //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-method 1319 | //go:noescape 1320 | func wasmimport_OutgoingRequestSetMethod(self0 uint32, method0 uint32, method1 *uint8, method2 uint32) (result0 uint32) 1321 | 1322 | // SetPathWithQuery represents the imported method "set-path-with-query". 1323 | // 1324 | // Set the combination of the HTTP Path and Query for the Request. 1325 | // When `none`, this represents an empty Path and empty Query. Fails is the 1326 | // string given is not a syntactically valid path and query uri component. 1327 | // 1328 | // set-path-with-query: func(path-with-query: option) -> result 1329 | // 1330 | //go:nosplit 1331 | func (self OutgoingRequest) SetPathWithQuery(pathWithQuery cm.Option[string]) (result cm.BoolResult) { 1332 | self0 := cm.Reinterpret[uint32](self) 1333 | pathWithQuery0, pathWithQuery1, pathWithQuery2 := lower_OptionString(pathWithQuery) 1334 | result0 := wasmimport_OutgoingRequestSetPathWithQuery((uint32)(self0), (uint32)(pathWithQuery0), (*uint8)(pathWithQuery1), (uint32)(pathWithQuery2)) 1335 | result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) 1336 | return 1337 | } 1338 | 1339 | //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-path-with-query 1340 | //go:noescape 1341 | func wasmimport_OutgoingRequestSetPathWithQuery(self0 uint32, pathWithQuery0 uint32, pathWithQuery1 *uint8, pathWithQuery2 uint32) (result0 uint32) 1342 | 1343 | // SetScheme represents the imported method "set-scheme". 1344 | // 1345 | // Set the HTTP Related Scheme for the Request. When `none`, the 1346 | // implementation may choose an appropriate default scheme. Fails if the 1347 | // string given is not a syntactically valid uri scheme. 1348 | // 1349 | // set-scheme: func(scheme: option) -> result 1350 | // 1351 | //go:nosplit 1352 | func (self OutgoingRequest) SetScheme(scheme cm.Option[Scheme]) (result cm.BoolResult) { 1353 | self0 := cm.Reinterpret[uint32](self) 1354 | scheme0, scheme1, scheme2, scheme3 := lower_OptionScheme(scheme) 1355 | result0 := wasmimport_OutgoingRequestSetScheme((uint32)(self0), (uint32)(scheme0), (uint32)(scheme1), (*uint8)(scheme2), (uint32)(scheme3)) 1356 | result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) 1357 | return 1358 | } 1359 | 1360 | //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-request.set-scheme 1361 | //go:noescape 1362 | func wasmimport_OutgoingRequestSetScheme(self0 uint32, scheme0 uint32, scheme1 uint32, scheme2 *uint8, scheme3 uint32) (result0 uint32) 1363 | 1364 | // RequestOptions represents the imported resource "wasi:http/types@0.2.0#request-options". 1365 | // 1366 | // Parameters for making an HTTP Request. Each of these parameters is 1367 | // currently an optional timeout applicable to the transport layer of the 1368 | // HTTP protocol. 1369 | // 1370 | // These timeouts are separate from any the user may use to bound a 1371 | // blocking call to `wasi:io/poll.poll`. 1372 | // 1373 | // resource request-options 1374 | type RequestOptions cm.Resource 1375 | 1376 | // ResourceDrop represents the imported resource-drop for resource "request-options". 1377 | // 1378 | // Drops a resource handle. 1379 | // 1380 | //go:nosplit 1381 | func (self RequestOptions) ResourceDrop() { 1382 | self0 := cm.Reinterpret[uint32](self) 1383 | wasmimport_RequestOptionsResourceDrop((uint32)(self0)) 1384 | return 1385 | } 1386 | 1387 | //go:wasmimport wasi:http/types@0.2.0 [resource-drop]request-options 1388 | //go:noescape 1389 | func wasmimport_RequestOptionsResourceDrop(self0 uint32) 1390 | 1391 | // NewRequestOptions represents the imported constructor for resource "request-options". 1392 | // 1393 | // Construct a default `request-options` value. 1394 | // 1395 | // constructor() 1396 | // 1397 | //go:nosplit 1398 | func NewRequestOptions() (result RequestOptions) { 1399 | result0 := wasmimport_NewRequestOptions() 1400 | result = cm.Reinterpret[RequestOptions]((uint32)(result0)) 1401 | return 1402 | } 1403 | 1404 | //go:wasmimport wasi:http/types@0.2.0 [constructor]request-options 1405 | //go:noescape 1406 | func wasmimport_NewRequestOptions() (result0 uint32) 1407 | 1408 | // BetweenBytesTimeout represents the imported method "between-bytes-timeout". 1409 | // 1410 | // The timeout for receiving subsequent chunks of bytes in the Response 1411 | // body stream. 1412 | // 1413 | // between-bytes-timeout: func() -> option 1414 | // 1415 | //go:nosplit 1416 | func (self RequestOptions) BetweenBytesTimeout() (result cm.Option[monotonicclock.Duration]) { 1417 | self0 := cm.Reinterpret[uint32](self) 1418 | wasmimport_RequestOptionsBetweenBytesTimeout((uint32)(self0), &result) 1419 | return 1420 | } 1421 | 1422 | //go:wasmimport wasi:http/types@0.2.0 [method]request-options.between-bytes-timeout 1423 | //go:noescape 1424 | func wasmimport_RequestOptionsBetweenBytesTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) 1425 | 1426 | // ConnectTimeout represents the imported method "connect-timeout". 1427 | // 1428 | // The timeout for the initial connect to the HTTP Server. 1429 | // 1430 | // connect-timeout: func() -> option 1431 | // 1432 | //go:nosplit 1433 | func (self RequestOptions) ConnectTimeout() (result cm.Option[monotonicclock.Duration]) { 1434 | self0 := cm.Reinterpret[uint32](self) 1435 | wasmimport_RequestOptionsConnectTimeout((uint32)(self0), &result) 1436 | return 1437 | } 1438 | 1439 | //go:wasmimport wasi:http/types@0.2.0 [method]request-options.connect-timeout 1440 | //go:noescape 1441 | func wasmimport_RequestOptionsConnectTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) 1442 | 1443 | // FirstByteTimeout represents the imported method "first-byte-timeout". 1444 | // 1445 | // The timeout for receiving the first byte of the Response body. 1446 | // 1447 | // first-byte-timeout: func() -> option 1448 | // 1449 | //go:nosplit 1450 | func (self RequestOptions) FirstByteTimeout() (result cm.Option[monotonicclock.Duration]) { 1451 | self0 := cm.Reinterpret[uint32](self) 1452 | wasmimport_RequestOptionsFirstByteTimeout((uint32)(self0), &result) 1453 | return 1454 | } 1455 | 1456 | //go:wasmimport wasi:http/types@0.2.0 [method]request-options.first-byte-timeout 1457 | //go:noescape 1458 | func wasmimport_RequestOptionsFirstByteTimeout(self0 uint32, result *cm.Option[monotonicclock.Duration]) 1459 | 1460 | // SetBetweenBytesTimeout represents the imported method "set-between-bytes-timeout". 1461 | // 1462 | // Set the timeout for receiving subsequent chunks of bytes in the Response 1463 | // body stream. An error return value indicates that this timeout is not 1464 | // supported. 1465 | // 1466 | // set-between-bytes-timeout: func(duration: option) -> result 1467 | // 1468 | //go:nosplit 1469 | func (self RequestOptions) SetBetweenBytesTimeout(duration cm.Option[monotonicclock.Duration]) (result cm.BoolResult) { 1470 | self0 := cm.Reinterpret[uint32](self) 1471 | duration0, duration1 := lower_OptionDuration(duration) 1472 | result0 := wasmimport_RequestOptionsSetBetweenBytesTimeout((uint32)(self0), (uint32)(duration0), (uint64)(duration1)) 1473 | result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) 1474 | return 1475 | } 1476 | 1477 | //go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-between-bytes-timeout 1478 | //go:noescape 1479 | func wasmimport_RequestOptionsSetBetweenBytesTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) 1480 | 1481 | // SetConnectTimeout represents the imported method "set-connect-timeout". 1482 | // 1483 | // Set the timeout for the initial connect to the HTTP Server. An error 1484 | // return value indicates that this timeout is not supported. 1485 | // 1486 | // set-connect-timeout: func(duration: option) -> result 1487 | // 1488 | //go:nosplit 1489 | func (self RequestOptions) SetConnectTimeout(duration cm.Option[monotonicclock.Duration]) (result cm.BoolResult) { 1490 | self0 := cm.Reinterpret[uint32](self) 1491 | duration0, duration1 := lower_OptionDuration(duration) 1492 | result0 := wasmimport_RequestOptionsSetConnectTimeout((uint32)(self0), (uint32)(duration0), (uint64)(duration1)) 1493 | result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) 1494 | return 1495 | } 1496 | 1497 | //go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-connect-timeout 1498 | //go:noescape 1499 | func wasmimport_RequestOptionsSetConnectTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) 1500 | 1501 | // SetFirstByteTimeout represents the imported method "set-first-byte-timeout". 1502 | // 1503 | // Set the timeout for receiving the first byte of the Response body. An 1504 | // error return value indicates that this timeout is not supported. 1505 | // 1506 | // set-first-byte-timeout: func(duration: option) -> result 1507 | // 1508 | //go:nosplit 1509 | func (self RequestOptions) SetFirstByteTimeout(duration cm.Option[monotonicclock.Duration]) (result cm.BoolResult) { 1510 | self0 := cm.Reinterpret[uint32](self) 1511 | duration0, duration1 := lower_OptionDuration(duration) 1512 | result0 := wasmimport_RequestOptionsSetFirstByteTimeout((uint32)(self0), (uint32)(duration0), (uint64)(duration1)) 1513 | result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) 1514 | return 1515 | } 1516 | 1517 | //go:wasmimport wasi:http/types@0.2.0 [method]request-options.set-first-byte-timeout 1518 | //go:noescape 1519 | func wasmimport_RequestOptionsSetFirstByteTimeout(self0 uint32, duration0 uint32, duration1 uint64) (result0 uint32) 1520 | 1521 | // ResponseOutparam represents the imported resource "wasi:http/types@0.2.0#response-outparam". 1522 | // 1523 | // Represents the ability to send an HTTP Response. 1524 | // 1525 | // This resource is used by the `wasi:http/incoming-handler` interface to 1526 | // allow a Response to be sent corresponding to the Request provided as the 1527 | // other argument to `incoming-handler.handle`. 1528 | // 1529 | // resource response-outparam 1530 | type ResponseOutparam cm.Resource 1531 | 1532 | // ResourceDrop represents the imported resource-drop for resource "response-outparam". 1533 | // 1534 | // Drops a resource handle. 1535 | // 1536 | //go:nosplit 1537 | func (self ResponseOutparam) ResourceDrop() { 1538 | self0 := cm.Reinterpret[uint32](self) 1539 | wasmimport_ResponseOutparamResourceDrop((uint32)(self0)) 1540 | return 1541 | } 1542 | 1543 | //go:wasmimport wasi:http/types@0.2.0 [resource-drop]response-outparam 1544 | //go:noescape 1545 | func wasmimport_ResponseOutparamResourceDrop(self0 uint32) 1546 | 1547 | // ResponseOutparamSet represents the imported static function "set". 1548 | // 1549 | // Set the value of the `response-outparam` to either send a response, 1550 | // or indicate an error. 1551 | // 1552 | // This method consumes the `response-outparam` to ensure that it is 1553 | // called at most once. If it is never called, the implementation 1554 | // will respond with an error. 1555 | // 1556 | // The user may provide an `error` to `response` to allow the 1557 | // implementation determine how to respond with an HTTP error response. 1558 | // 1559 | // set: static func(param: response-outparam, response: result) 1561 | // 1562 | //go:nosplit 1563 | func ResponseOutparamSet(param ResponseOutparam, response cm.Result[ErrorCodeShape, OutgoingResponse, ErrorCode]) { 1564 | param0 := cm.Reinterpret[uint32](param) 1565 | response0, response1, response2, response3, response4, response5, response6, response7 := lower_ResultOutgoingResponseErrorCode(response) 1566 | wasmimport_ResponseOutparamSet((uint32)(param0), (uint32)(response0), (uint32)(response1), (uint32)(response2), (uint64)(response3), (uint32)(response4), (uint32)(response5), (uint32)(response6), (uint32)(response7)) 1567 | return 1568 | } 1569 | 1570 | //go:wasmimport wasi:http/types@0.2.0 [static]response-outparam.set 1571 | //go:noescape 1572 | func wasmimport_ResponseOutparamSet(param0 uint32, response0 uint32, response1 uint32, response2 uint32, response3 uint64, response4 uint32, response5 uint32, response6 uint32, response7 uint32) 1573 | 1574 | // StatusCode represents the u16 "wasi:http/types@0.2.0#status-code". 1575 | // 1576 | // This type corresponds to the HTTP standard Status Code. 1577 | // 1578 | // type status-code = u16 1579 | type StatusCode uint16 1580 | 1581 | // IncomingResponse represents the imported resource "wasi:http/types@0.2.0#incoming-response". 1582 | // 1583 | // Represents an incoming HTTP Response. 1584 | // 1585 | // resource incoming-response 1586 | type IncomingResponse cm.Resource 1587 | 1588 | // ResourceDrop represents the imported resource-drop for resource "incoming-response". 1589 | // 1590 | // Drops a resource handle. 1591 | // 1592 | //go:nosplit 1593 | func (self IncomingResponse) ResourceDrop() { 1594 | self0 := cm.Reinterpret[uint32](self) 1595 | wasmimport_IncomingResponseResourceDrop((uint32)(self0)) 1596 | return 1597 | } 1598 | 1599 | //go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-response 1600 | //go:noescape 1601 | func wasmimport_IncomingResponseResourceDrop(self0 uint32) 1602 | 1603 | // Consume represents the imported method "consume". 1604 | // 1605 | // Returns the incoming body. May be called at most once. Returns error 1606 | // if called additional times. 1607 | // 1608 | // consume: func() -> result 1609 | // 1610 | //go:nosplit 1611 | func (self IncomingResponse) Consume() (result cm.Result[IncomingBody, IncomingBody, struct{}]) { 1612 | self0 := cm.Reinterpret[uint32](self) 1613 | wasmimport_IncomingResponseConsume((uint32)(self0), &result) 1614 | return 1615 | } 1616 | 1617 | //go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.consume 1618 | //go:noescape 1619 | func wasmimport_IncomingResponseConsume(self0 uint32, result *cm.Result[IncomingBody, IncomingBody, struct{}]) 1620 | 1621 | // Headers represents the imported method "headers". 1622 | // 1623 | // Returns the headers from the incoming response. 1624 | // 1625 | // The returned `headers` resource is immutable: `set`, `append`, and 1626 | // `delete` operations will fail with `header-error.immutable`. 1627 | // 1628 | // This headers resource is a child: it must be dropped before the parent 1629 | // `incoming-response` is dropped. 1630 | // 1631 | // headers: func() -> headers 1632 | // 1633 | //go:nosplit 1634 | func (self IncomingResponse) Headers() (result Fields) { 1635 | self0 := cm.Reinterpret[uint32](self) 1636 | result0 := wasmimport_IncomingResponseHeaders((uint32)(self0)) 1637 | result = cm.Reinterpret[Fields]((uint32)(result0)) 1638 | return 1639 | } 1640 | 1641 | //go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.headers 1642 | //go:noescape 1643 | func wasmimport_IncomingResponseHeaders(self0 uint32) (result0 uint32) 1644 | 1645 | // Status represents the imported method "status". 1646 | // 1647 | // Returns the status code from the incoming response. 1648 | // 1649 | // status: func() -> status-code 1650 | // 1651 | //go:nosplit 1652 | func (self IncomingResponse) Status() (result StatusCode) { 1653 | self0 := cm.Reinterpret[uint32](self) 1654 | result0 := wasmimport_IncomingResponseStatus((uint32)(self0)) 1655 | result = (StatusCode)((uint32)(result0)) 1656 | return 1657 | } 1658 | 1659 | //go:wasmimport wasi:http/types@0.2.0 [method]incoming-response.status 1660 | //go:noescape 1661 | func wasmimport_IncomingResponseStatus(self0 uint32) (result0 uint32) 1662 | 1663 | // IncomingBody represents the imported resource "wasi:http/types@0.2.0#incoming-body". 1664 | // 1665 | // Represents an incoming HTTP Request or Response's Body. 1666 | // 1667 | // A body has both its contents - a stream of bytes - and a (possibly 1668 | // empty) set of trailers, indicating that the full contents of the 1669 | // body have been received. This resource represents the contents as 1670 | // an `input-stream` and the delivery of trailers as a `future-trailers`, 1671 | // and ensures that the user of this interface may only be consuming either 1672 | // the body contents or waiting on trailers at any given time. 1673 | // 1674 | // resource incoming-body 1675 | type IncomingBody cm.Resource 1676 | 1677 | // ResourceDrop represents the imported resource-drop for resource "incoming-body". 1678 | // 1679 | // Drops a resource handle. 1680 | // 1681 | //go:nosplit 1682 | func (self IncomingBody) ResourceDrop() { 1683 | self0 := cm.Reinterpret[uint32](self) 1684 | wasmimport_IncomingBodyResourceDrop((uint32)(self0)) 1685 | return 1686 | } 1687 | 1688 | //go:wasmimport wasi:http/types@0.2.0 [resource-drop]incoming-body 1689 | //go:noescape 1690 | func wasmimport_IncomingBodyResourceDrop(self0 uint32) 1691 | 1692 | // IncomingBodyFinish represents the imported static function "finish". 1693 | // 1694 | // Takes ownership of `incoming-body`, and returns a `future-trailers`. 1695 | // This function will trap if the `input-stream` child is still alive. 1696 | // 1697 | // finish: static func(this: incoming-body) -> future-trailers 1698 | // 1699 | //go:nosplit 1700 | func IncomingBodyFinish(this IncomingBody) (result FutureTrailers) { 1701 | this0 := cm.Reinterpret[uint32](this) 1702 | result0 := wasmimport_IncomingBodyFinish((uint32)(this0)) 1703 | result = cm.Reinterpret[FutureTrailers]((uint32)(result0)) 1704 | return 1705 | } 1706 | 1707 | //go:wasmimport wasi:http/types@0.2.0 [static]incoming-body.finish 1708 | //go:noescape 1709 | func wasmimport_IncomingBodyFinish(this0 uint32) (result0 uint32) 1710 | 1711 | // Stream represents the imported method "stream". 1712 | // 1713 | // Returns the contents of the body, as a stream of bytes. 1714 | // 1715 | // Returns success on first call: the stream representing the contents 1716 | // can be retrieved at most once. Subsequent calls will return error. 1717 | // 1718 | // The returned `input-stream` resource is a child: it must be dropped 1719 | // before the parent `incoming-body` is dropped, or consumed by 1720 | // `incoming-body.finish`. 1721 | // 1722 | // This invariant ensures that the implementation can determine whether 1723 | // the user is consuming the contents of the body, waiting on the 1724 | // `future-trailers` to be ready, or neither. This allows for network 1725 | // backpressure is to be applied when the user is consuming the body, 1726 | // and for that backpressure to not inhibit delivery of the trailers if 1727 | // the user does not read the entire body. 1728 | // 1729 | // %stream: func() -> result 1730 | // 1731 | //go:nosplit 1732 | func (self IncomingBody) Stream() (result cm.Result[streams.InputStream, streams.InputStream, struct{}]) { 1733 | self0 := cm.Reinterpret[uint32](self) 1734 | wasmimport_IncomingBodyStream((uint32)(self0), &result) 1735 | return 1736 | } 1737 | 1738 | //go:wasmimport wasi:http/types@0.2.0 [method]incoming-body.stream 1739 | //go:noescape 1740 | func wasmimport_IncomingBodyStream(self0 uint32, result *cm.Result[streams.InputStream, streams.InputStream, struct{}]) 1741 | 1742 | // FutureTrailers represents the imported resource "wasi:http/types@0.2.0#future-trailers". 1743 | // 1744 | // Represents a future which may eventaully return trailers, or an error. 1745 | // 1746 | // In the case that the incoming HTTP Request or Response did not have any 1747 | // trailers, this future will resolve to the empty set of trailers once the 1748 | // complete Request or Response body has been received. 1749 | // 1750 | // resource future-trailers 1751 | type FutureTrailers cm.Resource 1752 | 1753 | // ResourceDrop represents the imported resource-drop for resource "future-trailers". 1754 | // 1755 | // Drops a resource handle. 1756 | // 1757 | //go:nosplit 1758 | func (self FutureTrailers) ResourceDrop() { 1759 | self0 := cm.Reinterpret[uint32](self) 1760 | wasmimport_FutureTrailersResourceDrop((uint32)(self0)) 1761 | return 1762 | } 1763 | 1764 | //go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-trailers 1765 | //go:noescape 1766 | func wasmimport_FutureTrailersResourceDrop(self0 uint32) 1767 | 1768 | // Get represents the imported method "get". 1769 | // 1770 | // Returns the contents of the trailers, or an error which occured, 1771 | // once the future is ready. 1772 | // 1773 | // The outer `option` represents future readiness. Users can wait on this 1774 | // `option` to become `some` using the `subscribe` method. 1775 | // 1776 | // The outer `result` is used to retrieve the trailers or error at most 1777 | // once. It will be success on the first call in which the outer option 1778 | // is `some`, and error on subsequent calls. 1779 | // 1780 | // The inner `result` represents that either the HTTP Request or Response 1781 | // body, as well as any trailers, were received successfully, or that an 1782 | // error occured receiving them. The optional `trailers` indicates whether 1783 | // or not trailers were present in the body. 1784 | // 1785 | // When some `trailers` are returned by this method, the `trailers` 1786 | // resource is immutable, and a child. Use of the `set`, `append`, or 1787 | // `delete` methods will return an error, and the resource must be 1788 | // dropped before the parent `future-trailers` is dropped. 1789 | // 1790 | // get: func() -> option, error-code>>> 1791 | // 1792 | //go:nosplit 1793 | func (self FutureTrailers) Get() (result cm.Option[cm.Result[cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], struct{}]]) { 1794 | self0 := cm.Reinterpret[uint32](self) 1795 | wasmimport_FutureTrailersGet((uint32)(self0), &result) 1796 | return 1797 | } 1798 | 1799 | //go:wasmimport wasi:http/types@0.2.0 [method]future-trailers.get 1800 | //go:noescape 1801 | func wasmimport_FutureTrailersGet(self0 uint32, result *cm.Option[cm.Result[cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], cm.Result[ErrorCodeShape, cm.Option[Fields], ErrorCode], struct{}]]) 1802 | 1803 | // Subscribe represents the imported method "subscribe". 1804 | // 1805 | // Returns a pollable which becomes ready when either the trailers have 1806 | // been received, or an error has occured. When this pollable is ready, 1807 | // the `get` method will return `some`. 1808 | // 1809 | // subscribe: func() -> pollable 1810 | // 1811 | //go:nosplit 1812 | func (self FutureTrailers) Subscribe() (result poll.Pollable) { 1813 | self0 := cm.Reinterpret[uint32](self) 1814 | result0 := wasmimport_FutureTrailersSubscribe((uint32)(self0)) 1815 | result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) 1816 | return 1817 | } 1818 | 1819 | //go:wasmimport wasi:http/types@0.2.0 [method]future-trailers.subscribe 1820 | //go:noescape 1821 | func wasmimport_FutureTrailersSubscribe(self0 uint32) (result0 uint32) 1822 | 1823 | // OutgoingResponse represents the imported resource "wasi:http/types@0.2.0#outgoing-response". 1824 | // 1825 | // Represents an outgoing HTTP Response. 1826 | // 1827 | // resource outgoing-response 1828 | type OutgoingResponse cm.Resource 1829 | 1830 | // ResourceDrop represents the imported resource-drop for resource "outgoing-response". 1831 | // 1832 | // Drops a resource handle. 1833 | // 1834 | //go:nosplit 1835 | func (self OutgoingResponse) ResourceDrop() { 1836 | self0 := cm.Reinterpret[uint32](self) 1837 | wasmimport_OutgoingResponseResourceDrop((uint32)(self0)) 1838 | return 1839 | } 1840 | 1841 | //go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-response 1842 | //go:noescape 1843 | func wasmimport_OutgoingResponseResourceDrop(self0 uint32) 1844 | 1845 | // NewOutgoingResponse represents the imported constructor for resource "outgoing-response". 1846 | // 1847 | // Construct an `outgoing-response`, with a default `status-code` of `200`. 1848 | // If a different `status-code` is needed, it must be set via the 1849 | // `set-status-code` method. 1850 | // 1851 | // * `headers` is the HTTP Headers for the Response. 1852 | // 1853 | // constructor(headers: headers) 1854 | // 1855 | //go:nosplit 1856 | func NewOutgoingResponse(headers Fields) (result OutgoingResponse) { 1857 | headers0 := cm.Reinterpret[uint32](headers) 1858 | result0 := wasmimport_NewOutgoingResponse((uint32)(headers0)) 1859 | result = cm.Reinterpret[OutgoingResponse]((uint32)(result0)) 1860 | return 1861 | } 1862 | 1863 | //go:wasmimport wasi:http/types@0.2.0 [constructor]outgoing-response 1864 | //go:noescape 1865 | func wasmimport_NewOutgoingResponse(headers0 uint32) (result0 uint32) 1866 | 1867 | // Body represents the imported method "body". 1868 | // 1869 | // Returns the resource corresponding to the outgoing Body for this Response. 1870 | // 1871 | // Returns success on the first call: the `outgoing-body` resource for 1872 | // this `outgoing-response` can be retrieved at most once. Subsequent 1873 | // calls will return error. 1874 | // 1875 | // body: func() -> result 1876 | // 1877 | //go:nosplit 1878 | func (self OutgoingResponse) Body() (result cm.Result[OutgoingBody, OutgoingBody, struct{}]) { 1879 | self0 := cm.Reinterpret[uint32](self) 1880 | wasmimport_OutgoingResponseBody((uint32)(self0), &result) 1881 | return 1882 | } 1883 | 1884 | //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.body 1885 | //go:noescape 1886 | func wasmimport_OutgoingResponseBody(self0 uint32, result *cm.Result[OutgoingBody, OutgoingBody, struct{}]) 1887 | 1888 | // Headers represents the imported method "headers". 1889 | // 1890 | // Get the headers associated with the Request. 1891 | // 1892 | // The returned `headers` resource is immutable: `set`, `append`, and 1893 | // `delete` operations will fail with `header-error.immutable`. 1894 | // 1895 | // This headers resource is a child: it must be dropped before the parent 1896 | // `outgoing-request` is dropped, or its ownership is transfered to 1897 | // another component by e.g. `outgoing-handler.handle`. 1898 | // 1899 | // headers: func() -> headers 1900 | // 1901 | //go:nosplit 1902 | func (self OutgoingResponse) Headers() (result Fields) { 1903 | self0 := cm.Reinterpret[uint32](self) 1904 | result0 := wasmimport_OutgoingResponseHeaders((uint32)(self0)) 1905 | result = cm.Reinterpret[Fields]((uint32)(result0)) 1906 | return 1907 | } 1908 | 1909 | //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.headers 1910 | //go:noescape 1911 | func wasmimport_OutgoingResponseHeaders(self0 uint32) (result0 uint32) 1912 | 1913 | // SetStatusCode represents the imported method "set-status-code". 1914 | // 1915 | // Set the HTTP Status Code for the Response. Fails if the status-code 1916 | // given is not a valid http status code. 1917 | // 1918 | // set-status-code: func(status-code: status-code) -> result 1919 | // 1920 | //go:nosplit 1921 | func (self OutgoingResponse) SetStatusCode(statusCode StatusCode) (result cm.BoolResult) { 1922 | self0 := cm.Reinterpret[uint32](self) 1923 | statusCode0 := (uint32)(statusCode) 1924 | result0 := wasmimport_OutgoingResponseSetStatusCode((uint32)(self0), (uint32)(statusCode0)) 1925 | result = (cm.BoolResult)(cm.U32ToBool((uint32)(result0))) 1926 | return 1927 | } 1928 | 1929 | //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.set-status-code 1930 | //go:noescape 1931 | func wasmimport_OutgoingResponseSetStatusCode(self0 uint32, statusCode0 uint32) (result0 uint32) 1932 | 1933 | // StatusCode represents the imported method "status-code". 1934 | // 1935 | // Get the HTTP Status Code for the Response. 1936 | // 1937 | // status-code: func() -> status-code 1938 | // 1939 | //go:nosplit 1940 | func (self OutgoingResponse) StatusCode() (result StatusCode) { 1941 | self0 := cm.Reinterpret[uint32](self) 1942 | result0 := wasmimport_OutgoingResponseStatusCode((uint32)(self0)) 1943 | result = (StatusCode)((uint32)(result0)) 1944 | return 1945 | } 1946 | 1947 | //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-response.status-code 1948 | //go:noescape 1949 | func wasmimport_OutgoingResponseStatusCode(self0 uint32) (result0 uint32) 1950 | 1951 | // OutgoingBody represents the imported resource "wasi:http/types@0.2.0#outgoing-body". 1952 | // 1953 | // Represents an outgoing HTTP Request or Response's Body. 1954 | // 1955 | // A body has both its contents - a stream of bytes - and a (possibly 1956 | // empty) set of trailers, inducating the full contents of the body 1957 | // have been sent. This resource represents the contents as an 1958 | // `output-stream` child resource, and the completion of the body (with 1959 | // optional trailers) with a static function that consumes the 1960 | // `outgoing-body` resource, and ensures that the user of this interface 1961 | // may not write to the body contents after the body has been finished. 1962 | // 1963 | // If the user code drops this resource, as opposed to calling the static 1964 | // method `finish`, the implementation should treat the body as incomplete, 1965 | // and that an error has occured. The implementation should propogate this 1966 | // error to the HTTP protocol by whatever means it has available, 1967 | // including: corrupting the body on the wire, aborting the associated 1968 | // Request, or sending a late status code for the Response. 1969 | // 1970 | // resource outgoing-body 1971 | type OutgoingBody cm.Resource 1972 | 1973 | // ResourceDrop represents the imported resource-drop for resource "outgoing-body". 1974 | // 1975 | // Drops a resource handle. 1976 | // 1977 | //go:nosplit 1978 | func (self OutgoingBody) ResourceDrop() { 1979 | self0 := cm.Reinterpret[uint32](self) 1980 | wasmimport_OutgoingBodyResourceDrop((uint32)(self0)) 1981 | return 1982 | } 1983 | 1984 | //go:wasmimport wasi:http/types@0.2.0 [resource-drop]outgoing-body 1985 | //go:noescape 1986 | func wasmimport_OutgoingBodyResourceDrop(self0 uint32) 1987 | 1988 | // OutgoingBodyFinish represents the imported static function "finish". 1989 | // 1990 | // Finalize an outgoing body, optionally providing trailers. This must be 1991 | // called to signal that the response is complete. If the `outgoing-body` 1992 | // is dropped without calling `outgoing-body.finalize`, the implementation 1993 | // should treat the body as corrupted. 1994 | // 1995 | // Fails if the body's `outgoing-request` or `outgoing-response` was 1996 | // constructed with a Content-Length header, and the contents written 1997 | // to the body (via `write`) does not match the value given in the 1998 | // Content-Length. 1999 | // 2000 | // finish: static func(this: outgoing-body, trailers: option) -> result<_, 2001 | // error-code> 2002 | // 2003 | //go:nosplit 2004 | func OutgoingBodyFinish(this OutgoingBody, trailers cm.Option[Fields]) (result cm.Result[ErrorCode, struct{}, ErrorCode]) { 2005 | this0 := cm.Reinterpret[uint32](this) 2006 | trailers0, trailers1 := lower_OptionTrailers(trailers) 2007 | wasmimport_OutgoingBodyFinish((uint32)(this0), (uint32)(trailers0), (uint32)(trailers1), &result) 2008 | return 2009 | } 2010 | 2011 | //go:wasmimport wasi:http/types@0.2.0 [static]outgoing-body.finish 2012 | //go:noescape 2013 | func wasmimport_OutgoingBodyFinish(this0 uint32, trailers0 uint32, trailers1 uint32, result *cm.Result[ErrorCode, struct{}, ErrorCode]) 2014 | 2015 | // Write represents the imported method "write". 2016 | // 2017 | // Returns a stream for writing the body contents. 2018 | // 2019 | // The returned `output-stream` is a child resource: it must be dropped 2020 | // before the parent `outgoing-body` resource is dropped (or finished), 2021 | // otherwise the `outgoing-body` drop or `finish` will trap. 2022 | // 2023 | // Returns success on the first call: the `output-stream` resource for 2024 | // this `outgoing-body` may be retrieved at most once. Subsequent calls 2025 | // will return error. 2026 | // 2027 | // write: func() -> result 2028 | // 2029 | //go:nosplit 2030 | func (self OutgoingBody) Write() (result cm.Result[streams.OutputStream, streams.OutputStream, struct{}]) { 2031 | self0 := cm.Reinterpret[uint32](self) 2032 | wasmimport_OutgoingBodyWrite((uint32)(self0), &result) 2033 | return 2034 | } 2035 | 2036 | //go:wasmimport wasi:http/types@0.2.0 [method]outgoing-body.write 2037 | //go:noescape 2038 | func wasmimport_OutgoingBodyWrite(self0 uint32, result *cm.Result[streams.OutputStream, streams.OutputStream, struct{}]) 2039 | 2040 | // FutureIncomingResponse represents the imported resource "wasi:http/types@0.2.0#future-incoming-response". 2041 | // 2042 | // Represents a future which may eventaully return an incoming HTTP 2043 | // Response, or an error. 2044 | // 2045 | // This resource is returned by the `wasi:http/outgoing-handler` interface to 2046 | // provide the HTTP Response corresponding to the sent Request. 2047 | // 2048 | // resource future-incoming-response 2049 | type FutureIncomingResponse cm.Resource 2050 | 2051 | // ResourceDrop represents the imported resource-drop for resource "future-incoming-response". 2052 | // 2053 | // Drops a resource handle. 2054 | // 2055 | //go:nosplit 2056 | func (self FutureIncomingResponse) ResourceDrop() { 2057 | self0 := cm.Reinterpret[uint32](self) 2058 | wasmimport_FutureIncomingResponseResourceDrop((uint32)(self0)) 2059 | return 2060 | } 2061 | 2062 | //go:wasmimport wasi:http/types@0.2.0 [resource-drop]future-incoming-response 2063 | //go:noescape 2064 | func wasmimport_FutureIncomingResponseResourceDrop(self0 uint32) 2065 | 2066 | // Get represents the imported method "get". 2067 | // 2068 | // Returns the incoming HTTP Response, or an error, once one is ready. 2069 | // 2070 | // The outer `option` represents future readiness. Users can wait on this 2071 | // `option` to become `some` using the `subscribe` method. 2072 | // 2073 | // The outer `result` is used to retrieve the response or error at most 2074 | // once. It will be success on the first call in which the outer option 2075 | // is `some`, and error on subsequent calls. 2076 | // 2077 | // The inner `result` represents that either the incoming HTTP Response 2078 | // status and headers have recieved successfully, or that an error 2079 | // occured. Errors may also occur while consuming the response body, 2080 | // but those will be reported by the `incoming-body` and its 2081 | // `output-stream` child. 2082 | // 2083 | // get: func() -> option>> 2084 | // 2085 | //go:nosplit 2086 | func (self FutureIncomingResponse) Get() (result cm.Option[cm.Result[cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], struct{}]]) { 2087 | self0 := cm.Reinterpret[uint32](self) 2088 | wasmimport_FutureIncomingResponseGet((uint32)(self0), &result) 2089 | return 2090 | } 2091 | 2092 | //go:wasmimport wasi:http/types@0.2.0 [method]future-incoming-response.get 2093 | //go:noescape 2094 | func wasmimport_FutureIncomingResponseGet(self0 uint32, result *cm.Option[cm.Result[cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], cm.Result[ErrorCodeShape, IncomingResponse, ErrorCode], struct{}]]) 2095 | 2096 | // Subscribe represents the imported method "subscribe". 2097 | // 2098 | // Returns a pollable which becomes ready when either the Response has 2099 | // been received, or an error has occured. When this pollable is ready, 2100 | // the `get` method will return `some`. 2101 | // 2102 | // subscribe: func() -> pollable 2103 | // 2104 | //go:nosplit 2105 | func (self FutureIncomingResponse) Subscribe() (result poll.Pollable) { 2106 | self0 := cm.Reinterpret[uint32](self) 2107 | result0 := wasmimport_FutureIncomingResponseSubscribe((uint32)(self0)) 2108 | result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) 2109 | return 2110 | } 2111 | 2112 | //go:wasmimport wasi:http/types@0.2.0 [method]future-incoming-response.subscribe 2113 | //go:noescape 2114 | func wasmimport_FutureIncomingResponseSubscribe(self0 uint32) (result0 uint32) 2115 | 2116 | // HTTPErrorCode represents the imported function "http-error-code". 2117 | // 2118 | // Attempts to extract a http-related `error` from the wasi:io `error` 2119 | // provided. 2120 | // 2121 | // Stream operations which return 2122 | // `wasi:io/stream/stream-error::last-operation-failed` have a payload of 2123 | // type `wasi:io/error/error` with more information about the operation 2124 | // that failed. This payload can be passed through to this function to see 2125 | // if there's http-related information about the error to return. 2126 | // 2127 | // Note that this function is fallible because not all io-errors are 2128 | // http-related errors. 2129 | // 2130 | // http-error-code: func(err: borrow) -> option 2131 | // 2132 | //go:nosplit 2133 | func HTTPErrorCode(err ioerror.Error) (result cm.Option[ErrorCode]) { 2134 | err0 := cm.Reinterpret[uint32](err) 2135 | wasmimport_HTTPErrorCode((uint32)(err0), &result) 2136 | return 2137 | } 2138 | 2139 | //go:wasmimport wasi:http/types@0.2.0 http-error-code 2140 | //go:noescape 2141 | func wasmimport_HTTPErrorCode(err0 uint32, result *cm.Option[ErrorCode]) 2142 | -------------------------------------------------------------------------------- /lib/wasi/http/wasi/wasi.wit.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | // Package wasi represents the world "wasi:http/wasi@0.2.0". 4 | package wasi 5 | -------------------------------------------------------------------------------- /lib/wasi/io/error/empty.s: -------------------------------------------------------------------------------- 1 | // This file exists for testing this package without WebAssembly, 2 | // allowing empty function bodies with a //go:wasmimport directive. 3 | // See https://pkg.go.dev/cmd/compile for more information. 4 | -------------------------------------------------------------------------------- /lib/wasi/io/error/error.wit.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | // Package ioerror represents the imported interface "wasi:io/error@0.2.0". 4 | package ioerror 5 | 6 | import ( 7 | "github.com/ydnar/wasm-tools-go/cm" 8 | ) 9 | 10 | // Error represents the imported resource "wasi:io/error@0.2.0#error". 11 | // 12 | // A resource which represents some error information. 13 | // 14 | // The only method provided by this resource is `to-debug-string`, 15 | // which provides some human-readable information about the error. 16 | // 17 | // In the `wasi:io` package, this resource is returned through the 18 | // `wasi:io/streams/stream-error` type. 19 | // 20 | // To provide more specific error information, other interfaces may 21 | // provide functions to further "downcast" this error into more specific 22 | // error information. For example, `error`s returned in streams derived 23 | // from filesystem types to be described using the filesystem's own 24 | // error-code type, using the function 25 | // `wasi:filesystem/types/filesystem-error-code`, which takes a parameter 26 | // `borrow` and returns 27 | // `option`. 28 | // 29 | // The set of functions which can "downcast" an `error` into a more 30 | // concrete type is open. 31 | // 32 | // resource error 33 | type Error cm.Resource 34 | 35 | // ResourceDrop represents the imported resource-drop for resource "error". 36 | // 37 | // Drops a resource handle. 38 | // 39 | //go:nosplit 40 | func (self Error) ResourceDrop() { 41 | self0 := cm.Reinterpret[uint32](self) 42 | wasmimport_ErrorResourceDrop((uint32)(self0)) 43 | return 44 | } 45 | 46 | //go:wasmimport wasi:io/error@0.2.0 [resource-drop]error 47 | //go:noescape 48 | func wasmimport_ErrorResourceDrop(self0 uint32) 49 | 50 | // ToDebugString represents the imported method "to-debug-string". 51 | // 52 | // Returns a string that is suitable to assist humans in debugging 53 | // this error. 54 | // 55 | // WARNING: The returned string should not be consumed mechanically! 56 | // It may change across platforms, hosts, or other implementation 57 | // details. Parsing this string is a major platform-compatibility 58 | // hazard. 59 | // 60 | // to-debug-string: func() -> string 61 | // 62 | //go:nosplit 63 | func (self Error) ToDebugString() (result string) { 64 | self0 := cm.Reinterpret[uint32](self) 65 | wasmimport_ErrorToDebugString((uint32)(self0), &result) 66 | return 67 | } 68 | 69 | //go:wasmimport wasi:io/error@0.2.0 [method]error.to-debug-string 70 | //go:noescape 71 | func wasmimport_ErrorToDebugString(self0 uint32, result *string) 72 | -------------------------------------------------------------------------------- /lib/wasi/io/poll/empty.s: -------------------------------------------------------------------------------- 1 | // This file exists for testing this package without WebAssembly, 2 | // allowing empty function bodies with a //go:wasmimport directive. 3 | // See https://pkg.go.dev/cmd/compile for more information. 4 | -------------------------------------------------------------------------------- /lib/wasi/io/poll/poll.wit.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | // Package poll represents the imported interface "wasi:io/poll@0.2.0". 4 | // 5 | // A poll API intended to let users wait for I/O events on multiple handles 6 | // at once. 7 | package poll 8 | 9 | import ( 10 | "github.com/ydnar/wasm-tools-go/cm" 11 | ) 12 | 13 | // Pollable represents the imported resource "wasi:io/poll@0.2.0#pollable". 14 | // 15 | // `pollable` represents a single I/O event which may be ready, or not. 16 | // 17 | // resource pollable 18 | type Pollable cm.Resource 19 | 20 | // ResourceDrop represents the imported resource-drop for resource "pollable". 21 | // 22 | // Drops a resource handle. 23 | // 24 | //go:nosplit 25 | func (self Pollable) ResourceDrop() { 26 | self0 := cm.Reinterpret[uint32](self) 27 | wasmimport_PollableResourceDrop((uint32)(self0)) 28 | return 29 | } 30 | 31 | //go:wasmimport wasi:io/poll@0.2.0 [resource-drop]pollable 32 | //go:noescape 33 | func wasmimport_PollableResourceDrop(self0 uint32) 34 | 35 | // Block represents the imported method "block". 36 | // 37 | // `block` returns immediately if the pollable is ready, and otherwise 38 | // blocks until ready. 39 | // 40 | // This function is equivalent to calling `poll.poll` on a list 41 | // containing only this pollable. 42 | // 43 | // block: func() 44 | // 45 | //go:nosplit 46 | func (self Pollable) Block() { 47 | self0 := cm.Reinterpret[uint32](self) 48 | wasmimport_PollableBlock((uint32)(self0)) 49 | return 50 | } 51 | 52 | //go:wasmimport wasi:io/poll@0.2.0 [method]pollable.block 53 | //go:noescape 54 | func wasmimport_PollableBlock(self0 uint32) 55 | 56 | // Ready represents the imported method "ready". 57 | // 58 | // Return the readiness of a pollable. This function never blocks. 59 | // 60 | // Returns `true` when the pollable is ready, and `false` otherwise. 61 | // 62 | // ready: func() -> bool 63 | // 64 | //go:nosplit 65 | func (self Pollable) Ready() (result bool) { 66 | self0 := cm.Reinterpret[uint32](self) 67 | result0 := wasmimport_PollableReady((uint32)(self0)) 68 | result = cm.U32ToBool((uint32)(result0)) 69 | return 70 | } 71 | 72 | //go:wasmimport wasi:io/poll@0.2.0 [method]pollable.ready 73 | //go:noescape 74 | func wasmimport_PollableReady(self0 uint32) (result0 uint32) 75 | 76 | // Poll represents the imported function "poll". 77 | // 78 | // Poll for completion on a set of pollables. 79 | // 80 | // This function takes a list of pollables, which identify I/O sources of 81 | // interest, and waits until one or more of the events is ready for I/O. 82 | // 83 | // The result `list` contains one or more indices of handles in the 84 | // argument list that is ready for I/O. 85 | // 86 | // If the list contains more elements than can be indexed with a `u32` 87 | // value, this function traps. 88 | // 89 | // A timeout can be implemented by adding a pollable from the 90 | // wasi-clocks API to the list. 91 | // 92 | // This function does not return a `result`; polling in itself does not 93 | // do any I/O so it doesn't fail. If any of the I/O sources identified by 94 | // the pollables has an error, it is indicated by marking the source as 95 | // being reaedy for I/O. 96 | // 97 | // poll: func(in: list>) -> list 98 | // 99 | //go:nosplit 100 | func Poll(in cm.List[Pollable]) (result cm.List[uint32]) { 101 | in0, in1 := cm.LowerList(in) 102 | wasmimport_Poll((*Pollable)(in0), (uint32)(in1), &result) 103 | return 104 | } 105 | 106 | //go:wasmimport wasi:io/poll@0.2.0 poll 107 | //go:noescape 108 | func wasmimport_Poll(in0 *Pollable, in1 uint32, result *cm.List[uint32]) 109 | -------------------------------------------------------------------------------- /lib/wasi/io/streams/abi.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | package streams 4 | 5 | import ( 6 | "unsafe" 7 | ) 8 | 9 | // StreamErrorShape is used for storage in variant or result types. 10 | type StreamErrorShape struct { 11 | shape [unsafe.Sizeof(StreamError{})]byte 12 | } 13 | -------------------------------------------------------------------------------- /lib/wasi/io/streams/empty.s: -------------------------------------------------------------------------------- 1 | // This file exists for testing this package without WebAssembly, 2 | // allowing empty function bodies with a //go:wasmimport directive. 3 | // See https://pkg.go.dev/cmd/compile for more information. 4 | -------------------------------------------------------------------------------- /lib/wasi/io/streams/streams.wit.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | // Package streams represents the imported interface "wasi:io/streams@0.2.0". 4 | // 5 | // WASI I/O is an I/O abstraction API which is currently focused on providing 6 | // stream types. 7 | // 8 | // In the future, the component model is expected to add built-in stream types; 9 | // when it does, they are expected to subsume this API. 10 | package streams 11 | 12 | import ( 13 | ioerror "github.com/dev-wasm/dev-wasm-go/lib/wasi/io/error" 14 | "github.com/dev-wasm/dev-wasm-go/lib/wasi/io/poll" 15 | "github.com/ydnar/wasm-tools-go/cm" 16 | ) 17 | 18 | // StreamError represents the imported variant "wasi:io/streams@0.2.0#stream-error". 19 | // 20 | // An error for input-stream and output-stream operations. 21 | // 22 | // variant stream-error { 23 | // last-operation-failed(error), 24 | // closed, 25 | // } 26 | type StreamError cm.Variant[uint8, ioerror.Error, ioerror.Error] 27 | 28 | // StreamErrorLastOperationFailed returns a [StreamError] of case "last-operation-failed". 29 | // 30 | // The last operation (a write or flush) failed before completion. 31 | // 32 | // More information is available in the `error` payload. 33 | func StreamErrorLastOperationFailed(data ioerror.Error) StreamError { 34 | return cm.New[StreamError](0, data) 35 | } 36 | 37 | // LastOperationFailed returns a non-nil *[ioerror.Error] if [StreamError] represents the variant case "last-operation-failed". 38 | func (self *StreamError) LastOperationFailed() *ioerror.Error { 39 | return cm.Case[ioerror.Error](self, 0) 40 | } 41 | 42 | // StreamErrorClosed returns a [StreamError] of case "closed". 43 | // 44 | // The stream is closed: no more input will be accepted by the 45 | // stream. A closed output-stream will return this error on all 46 | // future operations. 47 | func StreamErrorClosed() StreamError { 48 | var data struct{} 49 | return cm.New[StreamError](1, data) 50 | } 51 | 52 | // Closed returns true if [StreamError] represents the variant case "closed". 53 | func (self *StreamError) Closed() bool { 54 | return self.Tag() == 1 55 | } 56 | 57 | // InputStream represents the imported resource "wasi:io/streams@0.2.0#input-stream". 58 | // 59 | // An input bytestream. 60 | // 61 | // `input-stream`s are *non-blocking* to the extent practical on underlying 62 | // platforms. I/O operations always return promptly; if fewer bytes are 63 | // promptly available than requested, they return the number of bytes promptly 64 | // available, which could even be zero. To wait for data to be available, 65 | // use the `subscribe` function to obtain a `pollable` which can be polled 66 | // for using `wasi:io/poll`. 67 | // 68 | // resource input-stream 69 | type InputStream cm.Resource 70 | 71 | // ResourceDrop represents the imported resource-drop for resource "input-stream". 72 | // 73 | // Drops a resource handle. 74 | // 75 | //go:nosplit 76 | func (self InputStream) ResourceDrop() { 77 | self0 := cm.Reinterpret[uint32](self) 78 | wasmimport_InputStreamResourceDrop((uint32)(self0)) 79 | return 80 | } 81 | 82 | //go:wasmimport wasi:io/streams@0.2.0 [resource-drop]input-stream 83 | //go:noescape 84 | func wasmimport_InputStreamResourceDrop(self0 uint32) 85 | 86 | // BlockingRead represents the imported method "blocking-read". 87 | // 88 | // Read bytes from a stream, after blocking until at least one byte can 89 | // be read. Except for blocking, behavior is identical to `read`. 90 | // 91 | // blocking-read: func(len: u64) -> result, stream-error> 92 | // 93 | //go:nosplit 94 | func (self InputStream) BlockingRead(len_ uint64) (result cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) { 95 | self0 := cm.Reinterpret[uint32](self) 96 | len0 := (uint64)(len_) 97 | wasmimport_InputStreamBlockingRead((uint32)(self0), (uint64)(len0), &result) 98 | return 99 | } 100 | 101 | //go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-read 102 | //go:noescape 103 | func wasmimport_InputStreamBlockingRead(self0 uint32, len0 uint64, result *cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) 104 | 105 | // BlockingSkip represents the imported method "blocking-skip". 106 | // 107 | // Skip bytes from a stream, after blocking until at least one byte 108 | // can be skipped. Except for blocking behavior, identical to `skip`. 109 | // 110 | // blocking-skip: func(len: u64) -> result 111 | // 112 | //go:nosplit 113 | func (self InputStream) BlockingSkip(len_ uint64) (result cm.Result[uint64, uint64, StreamError]) { 114 | self0 := cm.Reinterpret[uint32](self) 115 | len0 := (uint64)(len_) 116 | wasmimport_InputStreamBlockingSkip((uint32)(self0), (uint64)(len0), &result) 117 | return 118 | } 119 | 120 | //go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.blocking-skip 121 | //go:noescape 122 | func wasmimport_InputStreamBlockingSkip(self0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) 123 | 124 | // Read represents the imported method "read". 125 | // 126 | // Perform a non-blocking read from the stream. 127 | // 128 | // When the source of a `read` is binary data, the bytes from the source 129 | // are returned verbatim. When the source of a `read` is known to the 130 | // implementation to be text, bytes containing the UTF-8 encoding of the 131 | // text are returned. 132 | // 133 | // This function returns a list of bytes containing the read data, 134 | // when successful. The returned list will contain up to `len` bytes; 135 | // it may return fewer than requested, but not more. The list is 136 | // empty when no bytes are available for reading at this time. The 137 | // pollable given by `subscribe` will be ready when more bytes are 138 | // available. 139 | // 140 | // This function fails with a `stream-error` when the operation 141 | // encounters an error, giving `last-operation-failed`, or when the 142 | // stream is closed, giving `closed`. 143 | // 144 | // When the caller gives a `len` of 0, it represents a request to 145 | // read 0 bytes. If the stream is still open, this call should 146 | // succeed and return an empty list, or otherwise fail with `closed`. 147 | // 148 | // The `len` parameter is a `u64`, which could represent a list of u8 which 149 | // is not possible to allocate in wasm32, or not desirable to allocate as 150 | // as a return value by the callee. The callee may return a list of bytes 151 | // less than `len` in size while more bytes are available for reading. 152 | // 153 | // read: func(len: u64) -> result, stream-error> 154 | // 155 | //go:nosplit 156 | func (self InputStream) Read(len_ uint64) (result cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) { 157 | self0 := cm.Reinterpret[uint32](self) 158 | len0 := (uint64)(len_) 159 | wasmimport_InputStreamRead((uint32)(self0), (uint64)(len0), &result) 160 | return 161 | } 162 | 163 | //go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.read 164 | //go:noescape 165 | func wasmimport_InputStreamRead(self0 uint32, len0 uint64, result *cm.Result[cm.List[uint8], cm.List[uint8], StreamError]) 166 | 167 | // Skip represents the imported method "skip". 168 | // 169 | // Skip bytes from a stream. Returns number of bytes skipped. 170 | // 171 | // Behaves identical to `read`, except instead of returning a list 172 | // of bytes, returns the number of bytes consumed from the stream. 173 | // 174 | // skip: func(len: u64) -> result 175 | // 176 | //go:nosplit 177 | func (self InputStream) Skip(len_ uint64) (result cm.Result[uint64, uint64, StreamError]) { 178 | self0 := cm.Reinterpret[uint32](self) 179 | len0 := (uint64)(len_) 180 | wasmimport_InputStreamSkip((uint32)(self0), (uint64)(len0), &result) 181 | return 182 | } 183 | 184 | //go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.skip 185 | //go:noescape 186 | func wasmimport_InputStreamSkip(self0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) 187 | 188 | // Subscribe represents the imported method "subscribe". 189 | // 190 | // Create a `pollable` which will resolve once either the specified stream 191 | // has bytes available to read or the other end of the stream has been 192 | // closed. 193 | // The created `pollable` is a child resource of the `input-stream`. 194 | // Implementations may trap if the `input-stream` is dropped before 195 | // all derived `pollable`s created with this function are dropped. 196 | // 197 | // subscribe: func() -> pollable 198 | // 199 | //go:nosplit 200 | func (self InputStream) Subscribe() (result poll.Pollable) { 201 | self0 := cm.Reinterpret[uint32](self) 202 | result0 := wasmimport_InputStreamSubscribe((uint32)(self0)) 203 | result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) 204 | return 205 | } 206 | 207 | //go:wasmimport wasi:io/streams@0.2.0 [method]input-stream.subscribe 208 | //go:noescape 209 | func wasmimport_InputStreamSubscribe(self0 uint32) (result0 uint32) 210 | 211 | // OutputStream represents the imported resource "wasi:io/streams@0.2.0#output-stream". 212 | // 213 | // An output bytestream. 214 | // 215 | // `output-stream`s are *non-blocking* to the extent practical on 216 | // underlying platforms. Except where specified otherwise, I/O operations also 217 | // always return promptly, after the number of bytes that can be written 218 | // promptly, which could even be zero. To wait for the stream to be ready to 219 | // accept data, the `subscribe` function to obtain a `pollable` which can be 220 | // polled for using `wasi:io/poll`. 221 | // 222 | // resource output-stream 223 | type OutputStream cm.Resource 224 | 225 | // ResourceDrop represents the imported resource-drop for resource "output-stream". 226 | // 227 | // Drops a resource handle. 228 | // 229 | //go:nosplit 230 | func (self OutputStream) ResourceDrop() { 231 | self0 := cm.Reinterpret[uint32](self) 232 | wasmimport_OutputStreamResourceDrop((uint32)(self0)) 233 | return 234 | } 235 | 236 | //go:wasmimport wasi:io/streams@0.2.0 [resource-drop]output-stream 237 | //go:noescape 238 | func wasmimport_OutputStreamResourceDrop(self0 uint32) 239 | 240 | // BlockingFlush represents the imported method "blocking-flush". 241 | // 242 | // Request to flush buffered output, and block until flush completes 243 | // and stream is ready for writing again. 244 | // 245 | // blocking-flush: func() -> result<_, stream-error> 246 | // 247 | //go:nosplit 248 | func (self OutputStream) BlockingFlush() (result cm.Result[StreamError, struct{}, StreamError]) { 249 | self0 := cm.Reinterpret[uint32](self) 250 | wasmimport_OutputStreamBlockingFlush((uint32)(self0), &result) 251 | return 252 | } 253 | 254 | //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-flush 255 | //go:noescape 256 | func wasmimport_OutputStreamBlockingFlush(self0 uint32, result *cm.Result[StreamError, struct{}, StreamError]) 257 | 258 | // BlockingSplice represents the imported method "blocking-splice". 259 | // 260 | // Read from one stream and write to another, with blocking. 261 | // 262 | // This is similar to `splice`, except that it blocks until the 263 | // `output-stream` is ready for writing, and the `input-stream` 264 | // is ready for reading, before performing the `splice`. 265 | // 266 | // blocking-splice: func(src: borrow, len: u64) -> result 267 | // 268 | //go:nosplit 269 | func (self OutputStream) BlockingSplice(src InputStream, len_ uint64) (result cm.Result[uint64, uint64, StreamError]) { 270 | self0 := cm.Reinterpret[uint32](self) 271 | src0 := cm.Reinterpret[uint32](src) 272 | len0 := (uint64)(len_) 273 | wasmimport_OutputStreamBlockingSplice((uint32)(self0), (uint32)(src0), (uint64)(len0), &result) 274 | return 275 | } 276 | 277 | //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-splice 278 | //go:noescape 279 | func wasmimport_OutputStreamBlockingSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) 280 | 281 | // BlockingWriteAndFlush represents the imported method "blocking-write-and-flush". 282 | // 283 | // Perform a write of up to 4096 bytes, and then flush the stream. Block 284 | // until all of these operations are complete, or an error occurs. 285 | // 286 | // This is a convenience wrapper around the use of `check-write`, 287 | // `subscribe`, `write`, and `flush`, and is implemented with the 288 | // following pseudo-code: 289 | // 290 | // let pollable = this.subscribe(); 291 | // while !contents.is_empty() { 292 | // // Wait for the stream to become writable 293 | // pollable.block(); 294 | // let Ok(n) = this.check-write(); // eliding error handling 295 | // let len = min(n, contents.len()); 296 | // let (chunk, rest) = contents.split_at(len); 297 | // this.write(chunk ); // eliding error handling 298 | // contents = rest; 299 | // } 300 | // this.flush(); 301 | // // Wait for completion of `flush` 302 | // pollable.block(); 303 | // // Check for any errors that arose during `flush` 304 | // let _ = this.check-write(); // eliding error handling 305 | // 306 | // blocking-write-and-flush: func(contents: list) -> result<_, stream-error> 307 | // 308 | //go:nosplit 309 | func (self OutputStream) BlockingWriteAndFlush(contents cm.List[uint8]) (result cm.Result[StreamError, struct{}, StreamError]) { 310 | self0 := cm.Reinterpret[uint32](self) 311 | contents0, contents1 := cm.LowerList(contents) 312 | wasmimport_OutputStreamBlockingWriteAndFlush((uint32)(self0), (*uint8)(contents0), (uint32)(contents1), &result) 313 | return 314 | } 315 | 316 | //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-and-flush 317 | //go:noescape 318 | func wasmimport_OutputStreamBlockingWriteAndFlush(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.Result[StreamError, struct{}, StreamError]) 319 | 320 | // BlockingWriteZeroesAndFlush represents the imported method "blocking-write-zeroes-and-flush". 321 | // 322 | // Perform a write of up to 4096 zeroes, and then flush the stream. 323 | // Block until all of these operations are complete, or an error 324 | // occurs. 325 | // 326 | // This is a convenience wrapper around the use of `check-write`, 327 | // `subscribe`, `write-zeroes`, and `flush`, and is implemented with 328 | // the following pseudo-code: 329 | // 330 | // let pollable = this.subscribe(); 331 | // while num_zeroes != 0 { 332 | // // Wait for the stream to become writable 333 | // pollable.block(); 334 | // let Ok(n) = this.check-write(); // eliding error handling 335 | // let len = min(n, num_zeroes); 336 | // this.write-zeroes(len); // eliding error handling 337 | // num_zeroes -= len; 338 | // } 339 | // this.flush(); 340 | // // Wait for completion of `flush` 341 | // pollable.block(); 342 | // // Check for any errors that arose during `flush` 343 | // let _ = this.check-write(); // eliding error handling 344 | // 345 | // blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error> 346 | // 347 | //go:nosplit 348 | func (self OutputStream) BlockingWriteZeroesAndFlush(len_ uint64) (result cm.Result[StreamError, struct{}, StreamError]) { 349 | self0 := cm.Reinterpret[uint32](self) 350 | len0 := (uint64)(len_) 351 | wasmimport_OutputStreamBlockingWriteZeroesAndFlush((uint32)(self0), (uint64)(len0), &result) 352 | return 353 | } 354 | 355 | //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.blocking-write-zeroes-and-flush 356 | //go:noescape 357 | func wasmimport_OutputStreamBlockingWriteZeroesAndFlush(self0 uint32, len0 uint64, result *cm.Result[StreamError, struct{}, StreamError]) 358 | 359 | // CheckWrite represents the imported method "check-write". 360 | // 361 | // Check readiness for writing. This function never blocks. 362 | // 363 | // Returns the number of bytes permitted for the next call to `write`, 364 | // or an error. Calling `write` with more bytes than this function has 365 | // permitted will trap. 366 | // 367 | // When this function returns 0 bytes, the `subscribe` pollable will 368 | // become ready when this function will report at least 1 byte, or an 369 | // error. 370 | // 371 | // check-write: func() -> result 372 | // 373 | //go:nosplit 374 | func (self OutputStream) CheckWrite() (result cm.Result[uint64, uint64, StreamError]) { 375 | self0 := cm.Reinterpret[uint32](self) 376 | wasmimport_OutputStreamCheckWrite((uint32)(self0), &result) 377 | return 378 | } 379 | 380 | //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.check-write 381 | //go:noescape 382 | func wasmimport_OutputStreamCheckWrite(self0 uint32, result *cm.Result[uint64, uint64, StreamError]) 383 | 384 | // Flush represents the imported method "flush". 385 | // 386 | // Request to flush buffered output. This function never blocks. 387 | // 388 | // This tells the output-stream that the caller intends any buffered 389 | // output to be flushed. the output which is expected to be flushed 390 | // is all that has been passed to `write` prior to this call. 391 | // 392 | // Upon calling this function, the `output-stream` will not accept any 393 | // writes (`check-write` will return `ok(0)`) until the flush has 394 | // completed. The `subscribe` pollable will become ready when the 395 | // flush has completed and the stream can accept more writes. 396 | // 397 | // flush: func() -> result<_, stream-error> 398 | // 399 | //go:nosplit 400 | func (self OutputStream) Flush() (result cm.Result[StreamError, struct{}, StreamError]) { 401 | self0 := cm.Reinterpret[uint32](self) 402 | wasmimport_OutputStreamFlush((uint32)(self0), &result) 403 | return 404 | } 405 | 406 | //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.flush 407 | //go:noescape 408 | func wasmimport_OutputStreamFlush(self0 uint32, result *cm.Result[StreamError, struct{}, StreamError]) 409 | 410 | // Splice represents the imported method "splice". 411 | // 412 | // Read from one stream and write to another. 413 | // 414 | // The behavior of splice is equivelant to: 415 | // 1. calling `check-write` on the `output-stream` 416 | // 2. calling `read` on the `input-stream` with the smaller of the 417 | // `check-write` permitted length and the `len` provided to `splice` 418 | // 3. calling `write` on the `output-stream` with that read data. 419 | // 420 | // Any error reported by the call to `check-write`, `read`, or 421 | // `write` ends the splice and reports that error. 422 | // 423 | // This function returns the number of bytes transferred; it may be less 424 | // than `len`. 425 | // 426 | // splice: func(src: borrow, len: u64) -> result 427 | // 428 | //go:nosplit 429 | func (self OutputStream) Splice(src InputStream, len_ uint64) (result cm.Result[uint64, uint64, StreamError]) { 430 | self0 := cm.Reinterpret[uint32](self) 431 | src0 := cm.Reinterpret[uint32](src) 432 | len0 := (uint64)(len_) 433 | wasmimport_OutputStreamSplice((uint32)(self0), (uint32)(src0), (uint64)(len0), &result) 434 | return 435 | } 436 | 437 | //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.splice 438 | //go:noescape 439 | func wasmimport_OutputStreamSplice(self0 uint32, src0 uint32, len0 uint64, result *cm.Result[uint64, uint64, StreamError]) 440 | 441 | // Subscribe represents the imported method "subscribe". 442 | // 443 | // Create a `pollable` which will resolve once the output-stream 444 | // is ready for more writing, or an error has occured. When this 445 | // pollable is ready, `check-write` will return `ok(n)` with n>0, or an 446 | // error. 447 | // 448 | // If the stream is closed, this pollable is always ready immediately. 449 | // 450 | // The created `pollable` is a child resource of the `output-stream`. 451 | // Implementations may trap if the `output-stream` is dropped before 452 | // all derived `pollable`s created with this function are dropped. 453 | // 454 | // subscribe: func() -> pollable 455 | // 456 | //go:nosplit 457 | func (self OutputStream) Subscribe() (result poll.Pollable) { 458 | self0 := cm.Reinterpret[uint32](self) 459 | result0 := wasmimport_OutputStreamSubscribe((uint32)(self0)) 460 | result = cm.Reinterpret[poll.Pollable]((uint32)(result0)) 461 | return 462 | } 463 | 464 | //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.subscribe 465 | //go:noescape 466 | func wasmimport_OutputStreamSubscribe(self0 uint32) (result0 uint32) 467 | 468 | // Write represents the imported method "write". 469 | // 470 | // Perform a write. This function never blocks. 471 | // 472 | // When the destination of a `write` is binary data, the bytes from 473 | // `contents` are written verbatim. When the destination of a `write` is 474 | // known to the implementation to be text, the bytes of `contents` are 475 | // transcoded from UTF-8 into the encoding of the destination and then 476 | // written. 477 | // 478 | // Precondition: check-write gave permit of Ok(n) and contents has a 479 | // length of less than or equal to n. Otherwise, this function will trap. 480 | // 481 | // returns Err(closed) without writing if the stream has closed since 482 | // the last call to check-write provided a permit. 483 | // 484 | // write: func(contents: list) -> result<_, stream-error> 485 | // 486 | //go:nosplit 487 | func (self OutputStream) Write(contents cm.List[uint8]) (result cm.Result[StreamError, struct{}, StreamError]) { 488 | self0 := cm.Reinterpret[uint32](self) 489 | contents0, contents1 := cm.LowerList(contents) 490 | wasmimport_OutputStreamWrite((uint32)(self0), (*uint8)(contents0), (uint32)(contents1), &result) 491 | return 492 | } 493 | 494 | //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write 495 | //go:noescape 496 | func wasmimport_OutputStreamWrite(self0 uint32, contents0 *uint8, contents1 uint32, result *cm.Result[StreamError, struct{}, StreamError]) 497 | 498 | // WriteZeroes represents the imported method "write-zeroes". 499 | // 500 | // Write zeroes to a stream. 501 | // 502 | // This should be used precisely like `write` with the exact same 503 | // preconditions (must use check-write first), but instead of 504 | // passing a list of bytes, you simply pass the number of zero-bytes 505 | // that should be written. 506 | // 507 | // write-zeroes: func(len: u64) -> result<_, stream-error> 508 | // 509 | //go:nosplit 510 | func (self OutputStream) WriteZeroes(len_ uint64) (result cm.Result[StreamError, struct{}, StreamError]) { 511 | self0 := cm.Reinterpret[uint32](self) 512 | len0 := (uint64)(len_) 513 | wasmimport_OutputStreamWriteZeroes((uint32)(self0), (uint64)(len0), &result) 514 | return 515 | } 516 | 517 | //go:wasmimport wasi:io/streams@0.2.0 [method]output-stream.write-zeroes 518 | //go:noescape 519 | func wasmimport_OutputStreamWriteZeroes(self0 uint32, len0 uint64, result *cm.Result[StreamError, struct{}, StreamError]) 520 | -------------------------------------------------------------------------------- /lib/wasi/random/random/empty.s: -------------------------------------------------------------------------------- 1 | // This file exists for testing this package without WebAssembly, 2 | // allowing empty function bodies with a //go:wasmimport directive. 3 | // See https://pkg.go.dev/cmd/compile for more information. 4 | -------------------------------------------------------------------------------- /lib/wasi/random/random/random.wit.go: -------------------------------------------------------------------------------- 1 | // Code generated by wit-bindgen-go. DO NOT EDIT. 2 | 3 | // Package random represents the imported interface "wasi:random/random@0.2.0". 4 | // 5 | // WASI Random is a random data API. 6 | // 7 | // It is intended to be portable at least between Unix-family platforms and 8 | // Windows. 9 | package random 10 | 11 | import ( 12 | "github.com/ydnar/wasm-tools-go/cm" 13 | ) 14 | 15 | // GetRandomBytes represents the imported function "get-random-bytes". 16 | // 17 | // Return `len` cryptographically-secure random or pseudo-random bytes. 18 | // 19 | // This function must produce data at least as cryptographically secure and 20 | // fast as an adequately seeded cryptographically-secure pseudo-random 21 | // number generator (CSPRNG). It must not block, from the perspective of 22 | // the calling program, under any circumstances, including on the first 23 | // request and on requests for numbers of bytes. The returned data must 24 | // always be unpredictable. 25 | // 26 | // This function must always return fresh data. Deterministic environments 27 | // must omit this function, rather than implementing it with deterministic 28 | // data. 29 | // 30 | // get-random-bytes: func(len: u64) -> list 31 | // 32 | //go:nosplit 33 | func GetRandomBytes(len_ uint64) (result cm.List[uint8]) { 34 | len0 := (uint64)(len_) 35 | wasmimport_GetRandomBytes((uint64)(len0), &result) 36 | return 37 | } 38 | 39 | //go:wasmimport wasi:random/random@0.2.0 get-random-bytes 40 | //go:noescape 41 | func wasmimport_GetRandomBytes(len0 uint64, result *cm.List[uint8]) 42 | 43 | // GetRandomU64 represents the imported function "get-random-u64". 44 | // 45 | // Return a cryptographically-secure random or pseudo-random `u64` value. 46 | // 47 | // This function returns the same type of data as `get-random-bytes`, 48 | // represented as a `u64`. 49 | // 50 | // get-random-u64: func() -> u64 51 | // 52 | //go:nosplit 53 | func GetRandomU64() (result uint64) { 54 | result0 := wasmimport_GetRandomU64() 55 | result = (uint64)((uint64)(result0)) 56 | return 57 | } 58 | 59 | //go:wasmimport wasi:random/random@0.2.0 get-random-u64 60 | //go:noescape 61 | func wasmimport_GetRandomU64() (result0 uint64) 62 | -------------------------------------------------------------------------------- /lib/wasi/wasi.wit: -------------------------------------------------------------------------------- 1 | package wasi:http@0.2.0; 2 | 3 | world wasi { 4 | /// HTTP proxies have access to time and randomness. 5 | import wasi:clocks/wall-clock@0.2.0; 6 | import wasi:clocks/monotonic-clock@0.2.0; 7 | import wasi:random/random@0.2.0; 8 | 9 | /// Proxies have standard output and error streams which are expected to 10 | /// terminate in a developer-facing console provided by the host. 11 | import wasi:cli/stdout@0.2.0; 12 | import wasi:cli/stderr@0.2.0; 13 | 14 | /// TODO: this is a temporary workaround until component tooling is able to 15 | /// gracefully handle the absence of stdin. Hosts must return an eof stream 16 | /// for this import, which is what wasi-libc + tooling will do automatically 17 | /// when this import is properly removed. 18 | import wasi:cli/stdin@0.2.0; 19 | 20 | /// This is the default handler to use when user code simply wants to make an 21 | /// HTTP request (e.g., via `fetch()`). 22 | import outgoing-handler; 23 | 24 | /// The host delivers incoming HTTP requests to a component by calling the 25 | /// `handle` function of this exported interface. A host may arbitrarily reuse 26 | /// or not reuse component instance when delivering incoming HTTP requests and 27 | /// thus a component must be able to handle 0..N calls to `handle`. 28 | export incoming-handler; 29 | } 30 | -------------------------------------------------------------------------------- /lib/wasi_snapshot_preview1.reactor.0_2_0.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dev-wasm/dev-wasm-go/b653306ed695b99e35789a913088597c2dc1ae98/lib/wasi_snapshot_preview1.reactor.0_2_0.wasm -------------------------------------------------------------------------------- /lib/wasi_snapshot_preview1.reactor.2023_11_10.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dev-wasm/dev-wasm-go/b653306ed695b99e35789a913088597c2dc1ae98/lib/wasi_snapshot_preview1.reactor.2023_11_10.wasm -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | type WasmGo struct { 9 | Message string 10 | } 11 | 12 | func (w *WasmGo) Print() { 13 | fmt.Println(w.Message) 14 | } 15 | 16 | func (w *WasmGo) Write(file string, text string) error { 17 | return os.WriteFile(file, []byte(text), 0x444) 18 | } 19 | 20 | func (w *WasmGo) Copy(from string, to string) error { 21 | data, err := os.ReadFile(from) 22 | if err != nil { 23 | return err 24 | } 25 | return os.WriteFile(to, data, 0x444) 26 | } 27 | 28 | func main() { 29 | w := WasmGo{"Hello Go World!"} 30 | w.Print() 31 | if err := w.Write("test.txt", "This is a test\n"); err != nil { 32 | fmt.Printf("Error writing %s\n", err) 33 | return 34 | } 35 | fmt.Println("Wrote file") 36 | if err := w.Copy("test.txt", "test-2.txt"); err != nil { 37 | fmt.Printf("Error writing %s\n", err) 38 | return 39 | } 40 | fmt.Println("Copied file") 41 | } 42 | -------------------------------------------------------------------------------- /webserver/wagi/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/dev-wasm/dev-wasm-go/webserver/wagi 2 | 3 | go 1.19 4 | -------------------------------------------------------------------------------- /webserver/wagi/lighttpd.conf: -------------------------------------------------------------------------------- 1 | server.modules = ( 2 | "mod_auth", 3 | "mod_cgi", 4 | "mod_accesslog", 5 | "mod_compress", 6 | ) 7 | 8 | # Basic setup 9 | server.document-root = "/workspaces/dev-wasm-go/" 10 | server.port = 8080 11 | 12 | # Send logs to stderr 13 | server.errorlog = "/dev/stderr" 14 | accesslog.filename = "/dev/stderr" 15 | 16 | # Serve these files by default for '/' 17 | index-file.names = ( 18 | "wagi.wasm" 19 | ) 20 | 21 | # Use the wagi.sh handler for all files that end in wasm 22 | cgi.assign = ( 23 | ".wasm" => "/usr/bin/wagi.sh" 24 | ) -------------------------------------------------------------------------------- /webserver/wagi/wagi.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "net/url" 7 | "os" 8 | "strings" 9 | ) 10 | 11 | func makeRequest() (*http.Request, error) { 12 | uriString := os.Getenv("REQUEST_SCHEME") + "localhost" + os.Getenv("REQUEST_URI") 13 | url, err := url.Parse(uriString) 14 | if err != nil { 15 | return nil, err 16 | } 17 | result := &http.Request{ 18 | Method: os.Getenv("REQUEST_METHOD"), 19 | URL: url, 20 | } 21 | 22 | return result, nil 23 | } 24 | 25 | type WagiResponseWriter struct { 26 | headers http.Header 27 | } 28 | 29 | func (w *WagiResponseWriter) Header() http.Header { 30 | return w.headers 31 | } 32 | 33 | func (w *WagiResponseWriter) WriteHeader(code int) { 34 | fmt.Printf("HTTP/1.0 %d status\r\n", code) 35 | for key, value := range w.headers { 36 | fmt.Printf("%s: %s\r\n", key, strings.Join(value, ", ")) 37 | } 38 | fmt.Print("\r\n") 39 | } 40 | 41 | func (w *WagiResponseWriter) Write(buffer []byte) (int, error) { 42 | return fmt.Print(string(buffer)) 43 | } 44 | 45 | func Serve(fn func(http.ResponseWriter, *http.Request)) { 46 | req, err := makeRequest() 47 | 48 | if err != nil { 49 | fmt.Println("Content-type: text/plain") 50 | fmt.Println("\n") 51 | fmt.Println(err.Error()) 52 | return 53 | } 54 | 55 | rw := &WagiResponseWriter{ 56 | headers: make(http.Header), 57 | } 58 | fn(rw, req) 59 | } 60 | 61 | func HandleRequest(res http.ResponseWriter, req *http.Request) { 62 | res.Header().Add("Content-type", "text/html") 63 | res.WriteHeader(200) 64 | 65 | query := req.URL.Query() 66 | name := "Unknown" 67 | if val, ok := query["name"]; ok { 68 | name = val[0] 69 | } 70 | res.Write([]byte(fmt.Sprintf("

Hello %s!

\n", name))) 71 | } 72 | 73 | func main() { 74 | Serve(HandleRequest) 75 | } -------------------------------------------------------------------------------- /webserver/wasi-http/.gitignore: -------------------------------------------------------------------------------- 1 | wasi-http* 2 | -------------------------------------------------------------------------------- /webserver/wasi-http/Makefile: -------------------------------------------------------------------------------- 1 | .phony: clean run 2 | 3 | default: main.component.wasm 4 | 5 | wasi-http-0.2.0: 6 | wget https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.0.tar.gz 7 | tar -xzf v0.2.0.tar.gz ; rm v0.2.0.tar.gz 8 | 9 | main.wasm: ; tinygo build -o main.wasm -target=wasi main.go 10 | 11 | main.embed.wasm: main.wasm wasi-http-0.2.0 ; wasm-tools component embed wasi-http-0.2.0/wit -w proxy main.wasm -o main.embed.wasm 12 | 13 | main.component.wasm: main.embed.wasm ; wasm-tools component new main.embed.wasm -o main.component.wasm --adapt ../../lib/wasi_snapshot_preview1.reactor.0_2_0.wasm 14 | 15 | clean: ; rm -rf main*.wasm wasi-http-0.2.0 16 | 17 | run: main.component.wasm ; WASMTIME_BACKTRACE_DETAILS=1 wasmtime serve -Scommon -Dlogging=y main.component.wasm -------------------------------------------------------------------------------- /webserver/wasi-http/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/dev-wasm/dev-wasm-go/webserver/wasi-http 2 | 3 | go 1.22.0 4 | 5 | require github.com/dev-wasm/dev-wasm-go/lib v0.0.0 6 | 7 | require github.com/ydnar/wasm-tools-go v0.1.5 // indirect 8 | 9 | replace github.com/dev-wasm/dev-wasm-go/lib v0.0.0 => ../../lib 10 | -------------------------------------------------------------------------------- /webserver/wasi-http/go.sum: -------------------------------------------------------------------------------- 1 | github.com/ydnar/wasm-tools-go v0.1.5 h1:ah2WT4gH0IrmN29ZSsjgNC9SPsdXZ+KN+o9uTZqNVSI= 2 | github.com/ydnar/wasm-tools-go v0.1.5/go.mod h1:L3sDi5rbAMJNmMO5cpDRzYYhB0r9xIU0xgpKjwU0Adg= 3 | -------------------------------------------------------------------------------- /webserver/wasi-http/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "net/http" 7 | "unsafe" 8 | 9 | "github.com/dev-wasm/dev-wasm-go/lib/http/server/handler" 10 | ) 11 | 12 | // This is required for building the module for some reason 13 | // I don't think it should be. I'm probably doing something 14 | // wrong. 15 | // 16 | // fwiw, I think this is likely buggy and either leaks memory 17 | // or has race conditions. 18 | // 19 | //go:wasmexport cabi_realloc 20 | //export cabi_realloc 21 | func wasmexport_cabi_realloc(ptr, oldSize, align, newSize uint32) uint32 { 22 | if newSize == 0 { 23 | return align 24 | } 25 | arr := make([]uint8, newSize) 26 | newPtr := unsafe.Pointer(unsafe.SliceData(arr)) 27 | return uint32(uintptr(newPtr)) 28 | } 29 | 30 | var count = 0 31 | 32 | type myHandler struct{} 33 | 34 | func (h myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { 35 | count++ 36 | w.WriteHeader(200) 37 | w.Write([]byte(fmt.Sprintf("Hello from WASM! (%d) %s\n", count, r.URL.Path))) 38 | body, err := io.ReadAll(r.Body) 39 | if err != nil { 40 | w.Write([]byte(err.Error())) 41 | } else { 42 | w.Write(body) 43 | } 44 | w.Write([]byte("Headers\n")) 45 | for k, v := range r.Header { 46 | w.Write([]byte(k + v[0] + "\n")) 47 | } 48 | w.Write([]byte("Query\n")) 49 | for k, v := range r.URL.Query() { 50 | w.Write([]byte(k + ":" + v[0] + "\n")) 51 | } 52 | } 53 | 54 | func init() { 55 | // For some reason 56 | // http.Handle and http.HandleFunc aren't working :( 57 | handler.ListenAndServe(myHandler{}) 58 | } 59 | 60 | func main() {} 61 | --------------------------------------------------------------------------------