To gitea and beyond, let's go(-yco)

This commit is contained in:
2025-11-10 19:12:09 +01:00
parent 8f6133392d
commit 71a031342b
245 changed files with 83994 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
package middleware
import (
"net/http"
)
func RequestSizeLimitMiddleware(maxSize int64) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Body == nil || r.Body == http.NoBody {
next.ServeHTTP(w, r)
return
}
limitedBody := http.MaxBytesReader(w, r.Body, maxSize)
r.Body = limitedBody
defer func() {
if err := limitedBody.Close(); err != nil {
return
}
}()
next.ServeHTTP(w, r)
})
}
}
func DefaultRequestSizeLimitMiddleware() func(http.Handler) http.Handler {
return RequestSizeLimitMiddleware(1024 * 1024)
}