fix: apply default HTTP2 body limit

This commit is contained in:
2026-09-22 22:43:07 +08:00
parent 1487a96f67
commit 46c5c9406c

View File

@@ -209,15 +209,17 @@ func (s *Server) Serve(ctx context.Context, listener net.Listener) error {
}
s.mu.Unlock()
maxBodyBytes := s.MaxBodyBytes
if maxBodyBytes <= 0 {
maxBodyBytes = defaultMaxBodyBytes
}
requestHandler := http.Handler(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
if s.MaxBodyBytes > 0 {
if request.ContentLength > s.MaxBodyBytes {
_ = request.Body.Close()
http.Error(writer, "request body too large\n", http.StatusRequestEntityTooLarge)
return
}
request.Body = http.MaxBytesReader(writer, request.Body, s.MaxBodyBytes)
if request.ContentLength > maxBodyBytes {
_ = request.Body.Close()
http.Error(writer, "request body too large\n", http.StatusRequestEntityTooLarge)
return
}
request.Body = http.MaxBytesReader(writer, request.Body, maxBodyBytes)
s.handler.ServeHTTP(writer, request)
}))
gate := &requestGate{server: s, next: requestHandler, slots: s.requestSlots}