From 2e50563877b44d300af345415011b26d614ded0f Mon Sep 17 00:00:00 2001 From: yoyofx Date: Wed, 10 Jun 2020 12:08:17 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20set=20http=20response=20header=20bugs.?= =?UTF-8?q?=20BUG=E5=87=BA=E7=8E=B0=E5=9C=A8net/http=E4=B8=AD=EF=BC=8Cfast?= =?UTF-8?q?http=E6=B2=A1=E6=9C=89=E8=BF=99=E4=B8=AA=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82=20=E9=97=AE=E9=A2=98=E6=80=BB=E7=BB=93=EF=BC=9A=20Set?= =?UTF-8?q?=20Header=20->=20Set=20StatusCode=20,=20is=20right.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ActionResult/IActionResult.go | 3 ++- Context/HttpContext.go | 5 ++--- Examples/SimpleWeb/main.go | 1 + Framework/Version.go | 2 +- Router/MvcRouterHandler.go | 15 +++++++-------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ActionResult/IActionResult.go b/ActionResult/IActionResult.go index 06e6692e..a7634c66 100644 --- a/ActionResult/IActionResult.go +++ b/ActionResult/IActionResult.go @@ -13,6 +13,7 @@ type IActionResult interface { func writeContentType(w http.ResponseWriter, value []string) { header := w.Header() if val := header["Content-Type"]; len(val) == 0 { - header["Content-Type"] = value + w.Header().Set("content-type", value[0]) + //header["Content-Type"] = value } } diff --git a/Context/HttpContext.go b/Context/HttpContext.go index 44ab52c8..3f66aa76 100644 --- a/Context/HttpContext.go +++ b/Context/HttpContext.go @@ -352,15 +352,14 @@ func bodyAllowedForStatus(status int) bool { // ActionResult writes the response headers and calls render.ActionResult to render data. func (c *HttpContext) Render(code int, r ActionResult.IActionResult) { - c.Status(code) - if !bodyAllowedForStatus(code) { r.WriteContentType(c.Response) c.Response.WriteHeaderNow() return } - if err := r.Render(c.Response); err != nil { + if err := r.Render(c.Response.ResponseWriter); err != nil { panic(err) } + c.Status(code) } diff --git a/Examples/SimpleWeb/main.go b/Examples/SimpleWeb/main.go index f0690e9c..5be38730 100644 --- a/Examples/SimpleWeb/main.go +++ b/Examples/SimpleWeb/main.go @@ -21,6 +21,7 @@ func main() { //* Create the builder of Web host func CreateCustomBuilder() *YoyoGo.HostBuilder { return YoyoGo.NewWebHostBuilder(). + //UseHttp(). UseFastHttp(). //UseServer(YoyoGo.DefaultHttps(":8080", "./Certificate/server.pem", "./Certificate/server.key")). Configure(func(app *YoyoGo.ApplicationBuilder) { diff --git a/Framework/Version.go b/Framework/Version.go index 67238553..127ade76 100644 --- a/Framework/Version.go +++ b/Framework/Version.go @@ -1,5 +1,5 @@ package YoyoGo const ( - Version = "v1.4.9.2 pre-release" + Version = "v1.4.9.3 pre-release" ) diff --git a/Router/MvcRouterHandler.go b/Router/MvcRouterHandler.go index 3fdf3abc..826a16a9 100644 --- a/Router/MvcRouterHandler.go +++ b/Router/MvcRouterHandler.go @@ -5,7 +5,6 @@ import ( "github.com/maxzhang1985/yoyogo/Context" "github.com/maxzhang1985/yoyogo/Controller" "net/http" - "reflect" "strings" ) @@ -70,10 +69,10 @@ func (handler *MvcRouterHandler) Invoke(ctx *Context.HttpContext, pathComponents } -func findControllerAction() { - t := reflect.ValueOf(method.Object) - method.methodInfo = t.MethodByName(method.MethodName) - if !method.methodInfo.IsValid() { - return false - } -} +//func findControllerAction() { +// t := reflect.ValueOf(method.Object) +// method.methodInfo = t.MethodByName(method.MethodName) +// if !method.methodInfo.IsValid() { +// return false +// } +//}