Skip to content

Commit

Permalink
fixed set http response header bugs.
Browse files Browse the repository at this point in the history
BUG出现在net/http中,fasthttp没有这个问题。
问题总结:
Set Header -> Set StatusCode , is right.
  • Loading branch information
yoyofx committed Jun 10, 2020
1 parent ea8a7d1 commit 2e50563
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
3 changes: 2 additions & 1 deletion ActionResult/IActionResult.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
5 changes: 2 additions & 3 deletions Context/HttpContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions Examples/SimpleWeb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Framework/Version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package YoyoGo

const (
Version = "v1.4.9.2 pre-release"
Version = "v1.4.9.3 pre-release"
)
15 changes: 7 additions & 8 deletions Router/MvcRouterHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/maxzhang1985/yoyogo/Context"
"github.com/maxzhang1985/yoyogo/Controller"
"net/http"
"reflect"
"strings"
)

Expand Down Expand Up @@ -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
// }
//}

0 comments on commit 2e50563

Please sign in to comment.