Introduce a custom header which servers can return to request cloudflared to not buffer the response.

This commit is contained in:
Oliver Weichhold 2024-12-19 20:27:56 +01:00
parent c6901551e7
commit 83cd5b6cd1
1 changed files with 6 additions and 0 deletions

View File

@ -29,6 +29,8 @@ const (
contentTypeHeader = "content-type"
sseContentType = "text/event-stream"
grpcContentType = "application/grpc"
FlushResponseHeader = "cf-cloudflared-flush-response"
)
var (
@ -270,6 +272,10 @@ type ConnectedFuse interface {
// Helper method to let the caller know what content-types should require a flush on every
// write to a ResponseWriter.
func shouldFlush(headers http.Header) bool {
if headers.Get(FlushResponseHeader) == "yes" {
return true
}
if contentType := headers.Get(contentTypeHeader); contentType != "" {
contentType = strings.ToLower(contentType)
for _, c := range flushableContentTypes {