rename ngin to rest
This commit is contained in:
27
rest/handler/gunziphandler.go
Normal file
27
rest/handler/gunziphandler.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"zero/rest/httpx"
|
||||
)
|
||||
|
||||
const gzipEncoding = "gzip"
|
||||
|
||||
func GunzipHandler(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.Contains(r.Header.Get(httpx.ContentEncoding), gzipEncoding) {
|
||||
reader, err := gzip.NewReader(r.Body)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
r.Body = reader
|
||||
}
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user