(b []byte)
| 154 | } |
| 155 | |
| 156 | func (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 | |
| 183 | func (w *gzipResponseWriter) Flush() { |
| 184 | if !w.minLengthExceeded { |
no test coverage detected