mirror of
https://github.com/nlepage/go-wasm-http-server.git
synced 2025-03-10 17:29:10 +00:00
fix: Firefox does not have request.body ReadableStream
This commit is contained in:
parent
c93d379f20
commit
897626b7d1
Binary file not shown.
Binary file not shown.
Binary file not shown.
22
request.go
22
request.go
@ -6,6 +6,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"syscall/js"
|
||||
|
||||
promise "github.com/nlepage/go-js-promise"
|
||||
"github.com/nlepage/go-wasm-http-server/v2/internal/readablestream"
|
||||
"github.com/nlepage/go-wasm-http-server/v2/internal/safejs"
|
||||
)
|
||||
@ -30,7 +31,26 @@ func Request(uvalue js.Value) (*http.Request, error) {
|
||||
}
|
||||
|
||||
var bodyReader io.Reader
|
||||
if !body.IsUndefined() && !body.IsNull() {
|
||||
|
||||
if !body.IsNull() {
|
||||
// WORKAROUND: Firefox does not have request.body ReadableStream
|
||||
if body.IsUndefined() {
|
||||
blobp, err := value.Call("blob")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
blob, err := promise.Await(safejs.Unsafe(blobp))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
body, err = safejs.Safe(blob).Call("stream")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
r, err := body.Call("getReader")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -136,6 +136,7 @@ func (r *response) Context() context.Context {
|
||||
func (r *response) WriteError(str string) {
|
||||
slog.Error(str)
|
||||
if !r.wroteHeader {
|
||||
r.Header().Set("Content-Type", "text/plain")
|
||||
r.WriteHeader(500)
|
||||
_, _ = r.WriteString(str)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user