-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbd1d49
commit bfe1a6f
Showing
5 changed files
with
51 additions
and
32 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package home | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/AdguardTeam/AdGuardHome/internal/aghio" | ||
) | ||
|
||
// middlerware is a wrapper function signature. | ||
type middleware func(http.Handler) http.Handler | ||
|
||
// withMiddlewares consequently wraps h with all the middlewares. | ||
func withMiddlewares(h http.Handler, middlewares ...middleware) (wrapped http.Handler) { | ||
wrapped = h | ||
|
||
for _, mw := range middlewares { | ||
wrapped = mw(wrapped) | ||
} | ||
|
||
return wrapped | ||
} | ||
|
||
// RequestBodySizeLimit is maximum request body length in bytes. | ||
const RequestBodySizeLimit = 64 * 1024 | ||
|
||
// LimitRequestBody substitutes body of the request with LimitedReadCloser. | ||
func limitRequestBody(h http.Handler) (limited http.Handler) { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
r.Body = aghio.LimitReadCloser(r.Body, RequestBodySizeLimit) | ||
|
||
h.ServeHTTP(w, r) | ||
}) | ||
} | ||
|
||
// TODO(a.garipov): We currently have to use this, because everything registers | ||
// its HTTP handlers in http.DefaultServeMux. In the future, refactor our HTTP | ||
// API initialization process and stop using the gosh darn http.DefaultServeMux | ||
// for anything at all. Gosh darn global variables. | ||
func filterPProf(h http.Handler) (filtered http.Handler) { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if strings.HasPrefix(r.URL.Path, "/debug/pprof") { | ||
http.NotFound(w, r) | ||
|
||
return | ||
} | ||
|
||
h.ServeHTTP(w, r) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters