mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-27 18:57:04 +02:00
fix(middleware): stream header-only response rewrites without body buffering
Header-only modifiers no longer use LazyResponseModifier with buffering always enabled. They wrap the response with ModifyResponseWriter and return after invoking the next handler. Body modifiers still use LazyResponseModifier with canBufferAndModifyResponseBody. Add a regression test that uses a 64MiB Content-Length with a small body.
This commit is contained in:
@@ -213,14 +213,13 @@ func (m *Middleware) ServeHTTP(next http.HandlerFunc, w http.ResponseWriter, r *
|
||||
return
|
||||
}
|
||||
isBodyModifier := isBodyResponseModifier(exec)
|
||||
|
||||
shouldBuffer := canBufferAndModifyResponseBody
|
||||
if !isBodyModifier {
|
||||
// Header-only response modifiers do not need body rewrite capability checks.
|
||||
// We still respect max buffer limits and may fall back to passthrough for large bodies.
|
||||
shouldBuffer = func(http.Header) bool { return true }
|
||||
mrw := httputils.NewModifyResponseWriter(w, r, exec.modifyResponse)
|
||||
next(mrw, r)
|
||||
return
|
||||
}
|
||||
lrm := httputils.NewLazyResponseModifier(w, shouldBuffer)
|
||||
|
||||
lrm := httputils.NewLazyResponseModifier(w, canBufferAndModifyResponseBody)
|
||||
lrm.SetMaxBufferedBytes(maxModifiableBody)
|
||||
defer func() {
|
||||
_, err := lrm.FlushRelease()
|
||||
|
||||
Reference in New Issue
Block a user