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 (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/url"
|
||||||
"syscall/js"
|
"syscall/js"
|
||||||
|
|
||||||
promise "github.com/nlepage/go-js-promise"
|
promise "github.com/nlepage/go-js-promise"
|
||||||
@ -20,7 +20,11 @@ func Request(uvalue js.Value) (*http.Request, error) {
|
|||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -59,11 +63,12 @@ func Request(uvalue js.Value) (*http.Request, error) {
|
|||||||
bodyReader = readablestream.NewReader(r)
|
bodyReader = readablestream.NewReader(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
req := httptest.NewRequest(
|
req := &http.Request{
|
||||||
method,
|
Method: method,
|
||||||
url,
|
URL: u,
|
||||||
bodyReader,
|
Body: io.NopCloser(bodyReader),
|
||||||
)
|
Header: make(http.Header),
|
||||||
|
}
|
||||||
|
|
||||||
headers, err := value.Get("headers")
|
headers, err := value.Get("headers")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user