R: allow null body

This commit is contained in:
aki-0421 2023-04-26 12:56:33 +09:00
parent 086a224243
commit a19471694e
No known key found for this signature in database
GPG Key ID: 64A8CF6D437D166A
2 changed files with 7 additions and 0 deletions

View File

@ -43,6 +43,12 @@ func ToJSResponse(w *ResponseWriterBuffer) (js.Value, error) {
respInit.Set("status", status)
respInit.Set("statusText", http.StatusText(status))
respInit.Set("headers", ToJSHeader(w.Header()))
if status == http.StatusSwitchingProtocols ||
status == http.StatusNoContent ||
status == http.StatusResetContent ||
status == http.StatusNotModified {
return jsutil.ResponseClass.New(jsutil.Null, respInit), nil
}
readableStream := jsutil.ConvertReaderToReadableStream(w.Reader)
return jsutil.ResponseClass.New(readableStream, respInit), nil
}

View File

@ -18,6 +18,7 @@ var (
ErrorClass = Global.Get("Error")
ReadableStreamClass = Global.Get("ReadableStream")
DateClass = Global.Get("Date")
Null = js.ValueOf(nil)
)
func NewObject() js.Value {