mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
fix bugs of hono middleware support
This commit is contained in:
parent
6f021d5ba9
commit
4b95d7f98c
@ -37,10 +37,8 @@ func (c *Context) Request() *http.Request {
|
|||||||
return c.reqFunc()
|
return c.reqFunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) Header() Header {
|
func (c *Context) SetHeader(key, value string) {
|
||||||
return &header{
|
c.ctxObj.Call("header", key, value)
|
||||||
headerObj: c.ctxObj.Get("req").Get("headers"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) SetStatus(statusCode int) {
|
func (c *Context) SetStatus(statusCode int) {
|
||||||
@ -51,13 +49,13 @@ func (c *Context) ResponseBody() io.ReadCloser {
|
|||||||
return jsutil.ConvertReadableStreamToReadCloser(c.ctxObj.Get("res").Get("body"))
|
return jsutil.ConvertReadableStreamToReadCloser(c.ctxObj.Get("res").Get("body"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) SetResponseBody(body io.ReadCloser) {
|
func (c *Context) SetBody(body io.ReadCloser) {
|
||||||
var res js.Value
|
var bodyObj js.Value
|
||||||
if sr, ok := body.(jsutil.RawJSBodyGetter); ok {
|
if sr, ok := body.(jsutil.RawJSBodyGetter); ok {
|
||||||
res = jsutil.ResponseClass.New(sr, c.ctxObj.Get("res"))
|
bodyObj = sr.GetRawJSBody()
|
||||||
} else {
|
} else {
|
||||||
bodyObj := jsutil.ConvertReaderToReadableStream(body)
|
bodyObj = jsutil.ConvertReaderToReadableStream(body)
|
||||||
res = jsutil.ResponseClass.New(bodyObj, c.ctxObj.Get("res"))
|
|
||||||
}
|
}
|
||||||
c.ctxObj.Set("res", res)
|
respObj := c.ctxObj.Call("body", bodyObj)
|
||||||
|
c.ctxObj.Set("res", respObj)
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ func runHonoMiddleware(nextFnObj js.Value) error {
|
|||||||
if middleware == nil {
|
if middleware == nil {
|
||||||
return fmt.Errorf("ServeMiddleware must be called before runHonoMiddleware.")
|
return fmt.Errorf("ServeMiddleware must be called before runHonoMiddleware.")
|
||||||
}
|
}
|
||||||
c := newContext(jsutil.RuntimeContext)
|
c := newContext(jsutil.RuntimeContext.Get("ctx"))
|
||||||
next := func() {
|
next := func() {
|
||||||
jsutil.AwaitPromise(nextFnObj.Invoke())
|
jsutil.AwaitPromise(nextFnObj.Invoke())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user