FlushError is an alternative Flush returning an error. It delays the actual Flush of the underlying ResponseWriterWrapper until headers were written.
()
| 290 | // FlushError is an alternative Flush returning an error. It delays the actual Flush of the underlying |
| 291 | // ResponseWriterWrapper until headers were written. |
| 292 | func (rw *responseWriter) FlushError() error { |
| 293 | // WriteHeader wasn't called and is a CONNECT request, treat it as a success. |
| 294 | // otherwise, wait until header is written. |
| 295 | if rw.isConnect && !rw.wroteHeader && rw.statusCode == 0 { |
| 296 | rw.WriteHeader(http.StatusOK) |
| 297 | } |
| 298 | |
| 299 | if !rw.wroteHeader { |
| 300 | // flushing the underlying ResponseWriter will write header and status code, |
| 301 | // but we need to delay that until we can determine if we must encode and |
| 302 | // therefore add the Content-Encoding header; this happens in the first call |
| 303 | // to rw.Write (see bug in #4314) |
| 304 | return nil |
| 305 | } |
| 306 | // also flushes the encoder, if any |
| 307 | // see: https://github.com/jjiang-stripe/caddy-slow-gzip |
| 308 | if rw.w != nil { |
| 309 | err := rw.w.Flush() |
| 310 | if err != nil { |
| 311 | return err |
| 312 | } |
| 313 | } |
| 314 | //nolint:bodyclose |
| 315 | return http.NewResponseController(rw.ResponseWriter).Flush() |
| 316 | } |
| 317 | |
| 318 | // Write writes to the response. If the response qualifies, |
| 319 | // it is encoded using the encoder, which is initialized |
nothing calls this directly
no test coverage detected