Skip to content

Commit

Permalink
Pull request: home: inc req size for some apis
Browse files Browse the repository at this point in the history
Merge in DNS/adguard-home from 2666-req-body-lim to master

Updates #2666.

Squashed commit of the following:

commit a525974
Merge: 947703f 4416829
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Feb 11 13:48:06 2021 +0300

    Merge branch 'master' into 2666-req-body-lim

commit 947703f
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Feb 11 13:28:54 2021 +0300

    home: inc req size for some apis
  • Loading branch information
ainar-g committed Feb 11, 2021
1 parent 4416829 commit f016ae1
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,13 +17,20 @@ 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]).
- DNSCrypt queries weren't marked as such in logs ([#2662]).

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



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 f016ae1

Please sign in to comment.