mirror of
https://github.com/nlepage/go-wasm-http-server.git
synced 2025-03-10 17:29:10 +00:00
fix: TinyGo compatible packages
The net/http/httptest package isn't implemented in tinygo — this (minor) change swaps to creating the necessary http.Request struct directly (which needs an extra step or two). This *is not* enough to get TinyGo _working_ as a compiler for this repo, but the compilation succeeds now.
This commit is contained in:
parent
3cf36c41e2
commit
a16a847b26
19
request.go
19
request.go
@ -3,7 +3,7 @@ package wasmhttp
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"syscall/js"
|
||||
|
||||
promise "github.com/nlepage/go-js-promise"
|
||||
@ -20,7 +20,11 @@ func Request(uvalue js.Value) (*http.Request, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url, err := value.GetString("url")
|
||||
rawURL, err := value.GetString("url")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
u, err := url.Parse(rawURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -59,11 +63,12 @@ func Request(uvalue js.Value) (*http.Request, error) {
|
||||
bodyReader = readablestream.NewReader(r)
|
||||
}
|
||||
|
||||
req := httptest.NewRequest(
|
||||
method,
|
||||
url,
|
||||
bodyReader,
|
||||
)
|
||||
req := &http.Request{
|
||||
Method: method,
|
||||
URL: u,
|
||||
Body: io.NopCloser(bodyReader),
|
||||
Header: make(http.Header),
|
||||
}
|
||||
|
||||
headers, err := value.Get("headers")
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user