mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-25 14:26:58 +00:00
rm gzip
This commit is contained in:
parent
a107ce0a05
commit
64201735a9
2 changed files with 2 additions and 40 deletions
|
@ -1,37 +0,0 @@
|
|||
package gzip
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type gzipResponseWriter struct {
|
||||
Writer *gzip.Writer
|
||||
ResponseWriter http.ResponseWriter
|
||||
}
|
||||
|
||||
func (gz gzipResponseWriter) Header() http.Header {
|
||||
return gz.ResponseWriter.Header()
|
||||
}
|
||||
|
||||
func (gz gzipResponseWriter) Write(b []byte) (int, error) {
|
||||
return gz.Writer.Write(b)
|
||||
}
|
||||
|
||||
func (gz gzipResponseWriter) WriteHeader(statusCode int) {
|
||||
gz.ResponseWriter.WriteHeader(statusCode)
|
||||
}
|
||||
|
||||
func SetupCompression(handler http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
|
||||
handler(w, r)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Encoding", "gzip")
|
||||
gz := gzip.NewWriter(w)
|
||||
defer gz.Close()
|
||||
handler(gzipResponseWriter{Writer: gz, ResponseWriter: w}, r)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue