mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
改进ghttp.Server自定义错误状态码返回
This commit is contained in:
@ -140,7 +140,11 @@ func (r *Response) WriteStatus(status int, content...string) {
|
||||
if status != http.StatusOK {
|
||||
if f := r.request.Server.getStatusHandler(status, r.request); f != nil {
|
||||
f(r.request)
|
||||
r.WriteHeader(status)
|
||||
// 如果是http.StatusOK那么表示回调函数内部没有设置header status,
|
||||
// 那么这里就可以设置status,防止多次设置(http: multiple response.WriteHeader calls)
|
||||
if r.Status == http.StatusOK {
|
||||
r.WriteHeader(status)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user