MCPcopy
hub / github.com/labstack/echo / Write

Method Write

middleware/compress.go:156–181  ·  view source on GitHub ↗
(b []byte)

Source from the content-addressed store, hash-verified

154}
155
156func (w *gzipResponseWriter) Write(b []byte) (int, error) {
157 if w.Header().Get(echo.HeaderContentType) == "" {
158 w.Header().Set(echo.HeaderContentType, http.DetectContentType(b))
159 }
160 w.wroteBody = true
161
162 if !w.minLengthExceeded {
163 n, err := w.buffer.Write(b)
164
165 if w.buffer.Len() >= w.minLength {
166 w.minLengthExceeded = true
167
168 // The minimum length is exceeded, add Content-Encoding header and write the header
169 w.Header().Set(echo.HeaderContentEncoding, gzipScheme) // Issue #806
170 if w.wroteHeader {
171 w.ResponseWriter.WriteHeader(w.code)
172 }
173
174 return w.Writer.Write(w.buffer.Bytes())
175 }
176
177 return n, err
178 }
179
180 return w.Writer.Write(b)
181}
182
183func (w *gzipResponseWriter) Flush() {
184 if !w.minLengthExceeded {

Callers 1

FlushMethod · 0.45

Calls 4

SetMethod · 0.80
GetMethod · 0.45
HeaderMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected