mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
Merge pull request #78 from syumai/fix-fetch-resp
fix fetch response to use blob() instead of text()
This commit is contained in:
commit
ec4e8e5f27
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
dist
|
||||
build
|
||||
build
|
||||
.wrangler
|
@ -4,7 +4,6 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall/js"
|
||||
|
||||
"github.com/syumai/workers/internal/jsutil"
|
||||
@ -14,8 +13,8 @@ import (
|
||||
// - Response: https://developer.mozilla.org/docs/Web/API/Response
|
||||
func ToResponse(res js.Value) (*http.Response, error) {
|
||||
status := res.Get("status").Int()
|
||||
promise := res.Call("text")
|
||||
body, err := jsutil.AwaitPromise(promise)
|
||||
promise := res.Call("blob")
|
||||
blob, err := jsutil.AwaitPromise(promise)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -26,7 +25,7 @@ func ToResponse(res js.Value) (*http.Response, error) {
|
||||
Status: strconv.Itoa(status) + " " + res.Get("statusText").String(),
|
||||
StatusCode: status,
|
||||
Header: header,
|
||||
Body: io.NopCloser(strings.NewReader(body.String())),
|
||||
Body: io.NopCloser(jsutil.ConvertStreamReaderToReader(blob.Call("stream").Call("getReader"))),
|
||||
ContentLength: contentLength,
|
||||
}, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user