MCPcopy
hub / github.com/klauspost/compress / GzipResponseWriter

Struct GzipResponseWriter

gzhttp/compress.go:99–126  ·  view source on GitHub ↗

GzipResponseWriter provides an http.ResponseWriter interface, which gzips bytes before writing them to the underlying response. This doesn't close the writers, so don't forget to do that. It can be configured to skip response smaller than minSize.

Source from the content-addressed store, hash-verified

97// writers, so don't forget to do that.
98// It can be configured to skip response smaller than minSize.
99type GzipResponseWriter struct {
100 http.ResponseWriter
101 level int
102 gwFactory writer.GzipWriterFactory
103 gw writer.GzipWriter
104
105 // Zstd support
106 enc encoding
107 zstdLevel int
108 zstdFactory writer.ZstdWriterFactory
109 zw writer.ZstdWriter
110 zstdJitter []byte // Jitter to write as skippable frame on Close
111
112 code int // Saves the WriteHeader value.
113
114 minSize int // Specifies the minimum response size to gzip. If the response length is bigger than this value, it is compressed.
115 buf []byte // Holds the first part of the write before reaching the minSize or the end of the write.
116 ignore bool // If true, then we immediately passthru writes to the underlying ResponseWriter.
117 keepAcceptRanges bool // Keep "Accept-Ranges" header.
118 setContentType bool // Add content type, if missing and detected.
119 suffixETag string // Suffix to add to ETag header if response is compressed.
120 dropETag bool // Drop ETag header if response is compressed (supersedes suffixETag).
121 sha256Jitter bool // Use sha256 for jitter.
122 randomJitter string // Add random bytes to output as header field.
123 jitterBuffer int // Maximum buffer to accumulate before doing jitter.
124
125 contentTypeFilter func(ct string) bool // Only compress if the response is one of these content-types. All are accepted if empty.
126}
127
128type GzipResponseWriterWithCloseNotify struct {
129 *GzipResponseWriter

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected