treat 0 max request size limit as unlimited

This commit is contained in:
Umputun
2021-05-12 21:54:41 -05:00
parent dc39e2d090
commit a93bd40f8a
2 changed files with 76 additions and 1 deletions

View File

@@ -106,7 +106,7 @@ func (h *Http) Run(ctx context.Context) error {
h.headersHandler(h.ProxyHeaders),
h.accessLogHandler(h.AccessLog),
h.stdoutLogHandler(h.StdOutEnabled, logger.New(logger.Log(log.Default()), logger.Prefix("[INFO]")).Handler),
R.SizeLimit(h.MaxBodySize),
h.maxReqSizeHandler(h.MaxBodySize),
h.gzipHandler(),
)
@@ -335,6 +335,17 @@ func (h *Http) stdoutLogHandler(enable bool, lh func(next http.Handler) http.Han
}
}
func (h *Http) maxReqSizeHandler(maxSize int64) func(next http.Handler) http.Handler {
if maxSize <= 0 {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
next.ServeHTTP(w, r)
})
}
}
return R.SizeLimit(maxSize)
}
func (h *Http) makeHTTPServer(addr string, router http.Handler) *http.Server {
return &http.Server{
Addr: addr,