MCPcopy
hub / github.com/caddyserver/caddy / flushInterval

Method flushInterval

modules/caddyhttp/reverseproxy/streaming.go:243–264  ·  view source on GitHub ↗

flushInterval returns the p.FlushInterval value, conditionally overriding its value for a specific request/response.

(req *http.Request, res *http.Response)

Source from the content-addressed store, hash-verified

241// flushInterval returns the p.FlushInterval value, conditionally
242// overriding its value for a specific request/response.
243func (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//

Callers 1

finalizeResponseMethod · 0.95

Calls 3

isBidirectionalStreamMethod · 0.95
DurationMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected