改进ghttp.Server自定义错误状态码返回

This commit is contained in:
John
2018-05-04 16:59:00 +08:00
parent 2c604a62cf
commit 6c0e4bd9a7

View File

@ -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
}
}