Response buffer middleware doesn't handle Transfer-Encoding: chunked for streaming responses #165
-
ProblemThe current response buffer middleware only bypasses buffering for Real-world ImpactI encountered this issue when deploying an application using MessageBus for long-polling with chunk encoding. The application sets Current Behaviorfunc (w *bufferedResponseWriter) ShouldSwitchToUnbuffered() bool {
contentType, _, _ := strings.Cut(w.Header().Get("Content-Type"), ";")
return contentType == "text/event-stream"
}Proposed SolutionCheck for func (w *bufferedResponseWriter) ShouldSwitchToUnbuffered() bool {
// Check for explicit streaming content types
contentType, _, _ := strings.Cut(w.Header().Get("Content-Type"), ";")
if contentType == "text/event-stream" {
return true
}
// Check for chunked transfer encoding - indicates streaming response
if w.Header().Get("Transfer-Encoding") == "chunked" {
return true
}
return false
}JustificationWhen a server explicitly uses TestingI've already implemented comprehensive unit tests covering:
I apologize - I got a bit ahead of myself and already opened a pull request #164 before discovering the discussion-first workflow. I should have started here first! The PR includes the implementation and comprehensive tests, but I'm happy to close it and wait for discussion consensus before proceeding. I wanted to make sure the solution was well-tested, but I realize now I should have followed the proper process. Would this approach be valuable for kamal-proxy? Happy to adjust based on feedback here before moving forward. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
@Mubramaj thanks for this. I agree that Your linked PR looks great too; I'll get that into the next release. Thanks again. |
Beta Was this translation helpful? Give feedback.
@Mubramaj thanks for this. I agree that
Transfer-Encoding: chunkedis a good signal that the upstream expects to be able to deliver those chunks to the client immediately. Seems like a solid change to me 👍Your linked PR looks great too; I'll get that into the next release. Thanks again.