我正在看这种类型
type GzipResponseWriter struct {
gw *gzip.Writer
http.ResponseWriter
}
以及将要实现的功能
func (w GzipResponseWriter) Write(b []byte) (int, error) {
if _, ok := w.Header()["Content-Type"]; !ok {
// If content type is not set, infer it from the uncompressed body.
w.Header().Set("Content-Type", http.DetectContentType(b))
}
return w.gw.Write(b)
}
func (w GzipResponseWriter) Flush() {
w.gw.Flush()
if fw, ok := w.ResponseWriter.(http.Flusher); ok {
fw.Flush()
}
}
http.ResponseWriter是否与第二个字段相关? 为什么不 gw1 http.ResponseWriter?