代码拉取完成,页面将自动刷新
package responsewriter
import (
"bufio"
"fmt"
"net"
"net/http"
"reflect"
"strings"
)
type ContentTypeWriter struct {
http.ResponseWriter
}
func (c ContentTypeWriter) Write(b []byte) (int, error) {
found := false
for k := range c.Header() {
if strings.EqualFold(k, "Content-Type") {
found = true
break
}
}
if !found {
c.Header().Set("Content-Type", http.DetectContentType(b))
}
return c.ResponseWriter.Write(b)
}
func ContentType(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
writer := ContentTypeWriter{ResponseWriter: w}
handler.ServeHTTP(writer, r)
})
}
func (c ContentTypeWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
if hijacker, ok := c.ResponseWriter.(http.Hijacker); ok {
return hijacker.Hijack()
}
return nil, nil, fmt.Errorf("Upstream ResponseWriter of type %v does not implement http.Hijacker", reflect.TypeOf(c.ResponseWriter))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。