fix: apply default HTTP2 body limit
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user