Merge pull request #78 from syumai/fix-fetch-resp

fix fetch response to use blob() instead of text()
This commit is contained in:
syumai 2023-12-31 23:46:12 +09:00 committed by GitHub
commit ec4e8e5f27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
dist
build
.wrangler

View File

@ -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
}