fix(http): enhance Content-Length handling in ResponseModifier

- Introduced origContentLength and bodyModified fields to track original content length and body modification status.
- Updated ContentLength and ContentLengthStr methods to return accurate content length based on body modification state.
- Adjusted Write and FlushRelease methods to ensure proper handling of Content-Length header.
- Modified middleware to use the new ContentLengthStr method.
This commit is contained in:
yusing
2025-12-04 17:26:15 +08:00
parent 9cdc985fb0
commit c098fef615
3 changed files with 51 additions and 25 deletions

View File

@@ -88,7 +88,7 @@ var staticReqVarSubsMap = map[string]reqVarGetter{
var staticRespVarSubsMap = map[string]respVarGetter{
VarRespContentType: func(resp *ResponseModifier) string { return resp.Header().Get("Content-Type") },
VarRespContentLen: func(resp *ResponseModifier) string { return strconv.Itoa(resp.ContentLength()) },
VarRespContentLen: func(resp *ResponseModifier) string { return resp.ContentLengthStr() },
VarRespStatusCode: func(resp *ResponseModifier) string { return strconv.Itoa(resp.StatusCode()) },
}