Skip to content

Commit

Permalink
home: inc req size for some apis
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Feb 11, 2021
1 parent e64df20 commit 947703f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ and this project adheres to
## [v0.105.1] - 2021-02-24
-->

### Changed

- Increase the HTTP API request body size limit for the `/control/access/set`
API ([#2666]).

### Fixed

- Set the request body size limit for HTTPS reqeusts as well.
- Incorrect version tag in the Docker release ([#2663]).

[#2663]: https://github.com/AdguardTeam/AdGuardHome/issues/2663
[#2666]: https://github.com/AdguardTeam/AdGuardHome/issues/2666

## [v0.105.0] - 2021-02-10

Expand Down
12 changes: 11 additions & 1 deletion internal/home/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ const RequestBodySizeLimit = 64 * 1024
func limitRequestBody(h http.Handler) (limited http.Handler) {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var err error
r.Body, err = aghio.LimitReadCloser(r.Body, RequestBodySizeLimit)

var bodySizeLimit int64 = RequestBodySizeLimit
if u := r.URL; u.Path == "/control/access/set" {
// An exception for a poorly designed API. Remove once
// the new, better API is up.
//
// See https://github.com/AdguardTeam/AdGuardHome/issues/2666.
bodySizeLimit *= 4
}

r.Body, err = aghio.LimitReadCloser(r.Body, bodySizeLimit)
if err != nil {
log.Error("limitRequestBody: %s", err)

Expand Down
2 changes: 1 addition & 1 deletion internal/home/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (web *Web) tlsServerLoop() {
RootCAs: Context.tlsRoots,
CipherSuites: Context.tlsCiphers,
},
Handler: Context.mux,
Handler: withMiddlewares(Context.mux, limitRequestBody),
ReadTimeout: web.conf.ReadTimeout,
ReadHeaderTimeout: web.conf.ReadHeaderTimeout,
WriteTimeout: web.conf.WriteTimeout,
Expand Down

0 comments on commit 947703f

Please sign in to comment.