mirror of
https://github.com/nlepage/go-wasm-http-server.git
synced 2026-01-12 01:59:14 +00:00
🚧
This commit is contained in:
@@ -24,18 +24,22 @@ func NewResponseWriter() *ResponseWriter {
|
||||
|
||||
var _ http.ResponseWriter = (*ResponseWriter)(nil)
|
||||
|
||||
// Header implements http.ResponseWriter.Header
|
||||
func (rw *ResponseWriter) Header() http.Header {
|
||||
return rw.header
|
||||
}
|
||||
|
||||
// Write implements http.ResponseWriter.Write
|
||||
func (rw *ResponseWriter) Write(p []byte) (int, error) {
|
||||
return rw.buf.Write(p)
|
||||
}
|
||||
|
||||
// WriteHeader implements http.ResponseWriter.WriteHeader
|
||||
func (rw *ResponseWriter) WriteHeader(statusCode int) {
|
||||
rw.statusCode = statusCode
|
||||
}
|
||||
|
||||
// JSResponse builds and returns the equivalent JS Response
|
||||
func (rw *ResponseWriter) JSResponse() js.Value {
|
||||
init := js.Global().Get("Object").New()
|
||||
|
||||
@@ -43,7 +47,9 @@ func (rw *ResponseWriter) JSResponse() js.Value {
|
||||
init.Set("status", rw.statusCode)
|
||||
}
|
||||
|
||||
//FIXME headers
|
||||
if len(rw.header) != 0 {
|
||||
init.Set("headers", map[string][]string(rw.header))
|
||||
}
|
||||
|
||||
jsBody := js.Global().Get("Uint8Array").New(rw.buf.Len())
|
||||
js.CopyBytesToJS(jsBody, rw.buf.Bytes())
|
||||
|
||||
Reference in New Issue
Block a user