2023-04-11 21:33:52 +09:00
|
|
|
package fetch
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"syscall/js"
|
|
|
|
)
|
|
|
|
|
|
|
|
// transport is an implementation of http.RoundTripper
|
|
|
|
type transport struct {
|
|
|
|
// namespace - Objects that Fetch API belongs to. Default is Global
|
|
|
|
namespace js.Value
|
2023-05-28 13:04:35 +09:00
|
|
|
redirect RedirectMode
|
2023-04-11 21:33:52 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// RoundTrip replaces http.DefaultTransport.RoundTrip to use cloudflare fetch
|
|
|
|
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
2023-05-28 13:04:35 +09:00
|
|
|
return fetch(t.namespace, req, &RequestInit{
|
|
|
|
Redirect: t.redirect,
|
|
|
|
})
|
2023-04-11 21:33:52 +09:00
|
|
|
}
|