gomod
parent
2e227088e2
commit
94b595af26
|
|
@ -3,6 +3,7 @@ package gziphttp
|
|||
import (
|
||||
"compress/gzip"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type GZipResponseWriter struct {
|
||||
|
|
@ -10,6 +11,19 @@ type GZipResponseWriter struct {
|
|||
gz *gzip.Writer
|
||||
}
|
||||
|
||||
func Can(r *http.Request) bool {
|
||||
encodings, _ := r.Header["Accept-Encoding"]
|
||||
for _, encoding := range encodings {
|
||||
items := strings.Split(encoding, ",")
|
||||
for _, item := range items {
|
||||
if strings.TrimSpace(item) == "gzip" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func New(w http.ResponseWriter) *GZipResponseWriter {
|
||||
w.Header().Add("Content-Type", "text/html")
|
||||
w.Header().Add("Content-Encoding", "gzip")
|
||||
|
|
|
|||
Loading…
Reference in New Issue