在同一次请求响应过程中,只能调用一次WriteHeader(code int),否则会有一条日志输出“http: superfluous response.WriteHeader call from”。如下所示:
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
w.WriteHeader(200) //重复调用
fmt.Fprintf(w, "Hello")
}