forked from yaitoo/xun
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompressor_gzip.go
More file actions
30 lines (24 loc) · 799 Bytes
/
compressor_gzip.go
File metadata and controls
30 lines (24 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package xun
import (
"compress/gzip"
"net/http"
)
// GzipCompressor is a struct that provides methods for compressing and decompressing data using the Gzip algorithm.
type GzipCompressor struct {
}
// AcceptEncoding returns the encoding type that the GzipCompressor supports.
// In this case, it returns "gzip".
func (c *GzipCompressor) AcceptEncoding() string {
return "gzip"
}
// New creates a new gzipResponseWriter that wraps the provided http.ResponseWriter.
// It sets the "Content-Encoding" header to "gzip" and returns the wrapped writer.
func (c *GzipCompressor) New(rw http.ResponseWriter) ResponseWriter {
rw.Header().Set("Content-Encoding", "gzip")
return &gzipResponseWriter{
w: gzip.NewWriter(rw),
stdResponseWriter: &stdResponseWriter{
ResponseWriter: rw,
},
}
}