Skip to content

Commit

Permalink
fixed panic on fetch returning empty response
Browse files Browse the repository at this point in the history
  • Loading branch information
syumai committed Aug 11, 2024
1 parent 50d520d commit cf3b68b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
2 changes: 1 addition & 1 deletion cloudflare/fetch/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ func fetch(namespace js.Value, req *http.Request, init *RequestInit) (*http.Resp
return nil, err
}

return jshttp.ToStreamResponse(jsRes)
return jshttp.ToResponse(jsRes)
}
11 changes: 0 additions & 11 deletions internal/jshttp/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ func ToResponse(res js.Value) (*http.Response, error) {
return toResponse(res, body)
}

// ToStreamResponse pipes JavaScript sides Response to TransformStream and converts to *http.Response.
// - see: https://developers.cloudflare.com/workers/runtime-apis/streams/
func ToStreamResponse(res js.Value) (*http.Response, error) {
ts := js.Global().Get("IdentityTransformStream").New()
readable := ts.Get("readable")
writable := ts.Get("writable")
res.Get("body").Call("pipeTo", writable)
body := jsutil.ConvertReadableStreamToReadCloser(readable)
return toResponse(res, body)
}

// ToJSResponse converts *http.Response to JavaScript sides Response class object.
func ToJSResponse(res *http.Response) js.Value {
return newJSResponse(res.StatusCode, res.Header, res.Body, nil)
Expand Down

0 comments on commit cf3b68b

Please sign in to comment.