diff --git a/README.md b/README.md index f721e95..9137591 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Import `go.wasmcloud.dev/component` in your Go module. Import the SDK WIT. In `wit/deps.toml`: ``` -wasmcloud-component = "https://github.com/wasmCloud/component-sdk-go/archive/.tar.gz" +wasmcloud-component = "https://github.com/wasmCloud/component-sdk-go/archive/main.tar.gz" ``` Run `wit-deps` to update your wit dependencies. @@ -28,6 +28,8 @@ And in your world definition: include wasmcloud:component/imports; ``` +# Adapters + ## net/wasihttp The `wasihttp` package provides an implementation of `http.Handler` backed by `wasi:http`, as well as a `http.RoundTripper` backed by `wasi:http`. @@ -48,7 +50,7 @@ func httpServe(w http.ResponseWriter, *r http.Request) { func init() { // request will be fulfilled via wasi:http/incoming-handler - wasihttp.Handle("/", httpServe) + wasihttp.HandleFunc("/", httpServe) } ``` @@ -87,3 +89,11 @@ logger.Info("Hello", slog.String("planet", "Earth")) ``` See `wasilog.Options` for log level & other configuration options. + +## Community + +Similar projects: + +- [rajatjindal/wasi-go-sdk](https://github.com/rajatjindal/wasi-go-sdk) +- [dev-wasm/dev-wasm-go](https://github.com/dev-wasm/dev-wasm-go) +- [Mossaka/hello-wasi-http-tinygo](https://github.com/Mossaka/hello-wasi-http-tinygo) diff --git a/net/wasihttp/adapter.go b/net/wasihttp/adapter.go index eb1a986..2c11421 100644 --- a/net/wasihttp/adapter.go +++ b/net/wasihttp/adapter.go @@ -1,5 +1,7 @@ package wasihttp +// Refactored from https://github.com/rajatjindal/wasi-go-sdk/tree/d3e8665bef9fbf0794ad14f7114a9882e0d983c3/pkg/wasihttp + import ( "fmt" "io" diff --git a/net/wasihttp/roundtripper.go b/net/wasihttp/roundtripper.go index fcaba62..6819429 100644 --- a/net/wasihttp/roundtripper.go +++ b/net/wasihttp/roundtripper.go @@ -51,7 +51,12 @@ func (r *Transport) RoundTrip(incomingRequest *http.Request) (*http.Response, er outRequest.SetAuthority(cm.Some(incomingRequest.Host)) outRequest.SetMethod(toWasiMethod(incomingRequest.Method)) - outRequest.SetPathWithQuery(cm.Some(incomingRequest.URL.Path + "?" + incomingRequest.URL.Query().Encode())) + + pathWithQuery := incomingRequest.URL.Path + if incomingRequest.URL.RawQuery != "" { + pathWithQuery = pathWithQuery + "?" + incomingRequest.URL.Query().Encode() + } + outRequest.SetPathWithQuery(cm.Some(pathWithQuery)) switch incomingRequest.URL.Scheme { case "http":