-
Notifications
You must be signed in to change notification settings - Fork 270
sdk/go: Override http.DefaultTransport #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Are you thinking something similar to: diff --git a/examples/http-tinygo-outbound-http/main.go b/examples/http-tinygo-outbound-http/main.go
index c00f286..cebfc89 100644
--- a/examples/http-tinygo-outbound-http/main.go
+++ b/examples/http-tinygo-outbound-http/main.go
@@ -31,5 +31,13 @@ func main() {
if err != nil {
fmt.Fprintf(os.Stderr, "Cannot send HTTP request: %v", err)
}
+
+ var client = http.DefaultClient
+ client.Transport = &spin_http.WASIHTTPTransport{}
+
+ _, err = client.Get("https://some-random-api.ml/facts/dog")
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Cannot send HTTP request: %v", err)
+ }
})
}
diff --git a/sdk/go/http/http.go b/sdk/go/http/http.go
index 5107011..5f4bd15 100644
--- a/sdk/go/http/http.go
+++ b/sdk/go/http/http.go
@@ -41,3 +41,12 @@ func Post(url string, contentType string, body io.Reader) (*http.Response, error
func Send(req *http.Request) (*http.Response, error) {
return send(req)
}
+
+// WASIHTTPTransport implements the Go http.RoundTripper interface so that
+// an http.Client can be used from a WASI application.
+type WASIHTTPTransport struct{}
+
+// RoundTrip implements the go.RoundTripper interface using the WASI outbound HTTP implementation.
+func (t *WASIHTTPTransport) RoundTrip(r *http.Request) (*http.Response, error) {
+ return Send(r)
+} This ends up compiling something related to timings (I assume because of timeouts), and it fails at runtime because of tinygo-org/tinygo#1037:
|
Yes, that is basically what I had in mind (though I believe you can set
That's unfortunate! Maybe we can just let this issue be our tracker for if/when that is resolved. |
If we can replace http.DefaultTransport with our implementation then most http libraries that make outbound http requests should magically work.
The text was updated successfully, but these errors were encountered: