Implement http.RoundTripper
EtienneBruines opened this issue · comments
To make the HTTP function more accessible to Go developers, it would be nice if go-pdk
implemented http.RoundTripper
to process standard HTTP requests. This way, a larger ecosystem of middleware can be used by plugins.
Ideally, this would allow a plugin like this:
package main
import (
"net/http"
"github.com/extism/go-pdk"
)
//export http_get_example1
func http_get_example1() int32 {
req, _ := http.NewRequest("GET", "https://example.org", nil)
resp, _ := pdk.HttpClient.Do(req)
// Process the response
return 0
}
//export http_get_example2
func http_get_example2() int32 {
client := http.Client{
RoundTripper: pdk.RoundTripper{},
}
req, _ := http.NewRequest("GET", "https://example.org", nil)
resp, _ := client.Do(req)
// Process the response
return 0
}
There might be quite some things that the pdk.RoundTripper
cannot support (streaming responses, for example). But since that's not supported anyways, we could just return an error
explaining what isn't supported. For basic requests/responses this should be relatively doable.
The `http.RoundTripper interface is an easy one to implement:
Thoughts?
Sorry, somehow we missed this issue. I'm definitely open to it! There is some overlap with our HTTP impl but we could probably re-use the objects.