flushInterval returns the p.FlushInterval value, conditionally overriding its value for a specific request/response.
(req *http.Request, res *http.Response)
| 241 | // flushInterval returns the p.FlushInterval value, conditionally |
| 242 | // overriding its value for a specific request/response. |
| 243 | func (h Handler) flushInterval(req *http.Request, res *http.Response) time.Duration { |
| 244 | resCTHeader := res.Header.Get("Content-Type") |
| 245 | resCT, _, err := mime.ParseMediaType(resCTHeader) |
| 246 | |
| 247 | // For Server-Sent Events responses, flush immediately. |
| 248 | // The MIME type is defined in https://www.w3.org/TR/eventsource/#text-event-stream |
| 249 | if err == nil && resCT == "text/event-stream" { |
| 250 | return -1 // negative means immediately |
| 251 | } |
| 252 | |
| 253 | // We might have the case of streaming for which Content-Length might be unset. |
| 254 | if res.ContentLength == -1 { |
| 255 | return -1 |
| 256 | } |
| 257 | |
| 258 | // for h2 and h2c upstream streaming data to client (issues #3556 and #3606) |
| 259 | if h.isBidirectionalStream(req, res) { |
| 260 | return -1 |
| 261 | } |
| 262 | |
| 263 | return time.Duration(h.FlushInterval) |
| 264 | } |
| 265 | |
| 266 | // isBidirectionalStream returns whether we should work in bi-directional stream mode. |
| 267 | // |
no test coverage detected