Skip to content

Commit

Permalink
all: fix minor inaccuracies
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Nov 20, 2020
1 parent 93462c7 commit f57a2f5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ and this project adheres to

### Added

- Limiting request's body size ([#2305]).
- HTTP API request body limit [#2305].

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

Expand All @@ -22,6 +22,8 @@ and this project adheres to
[#2271]: https://github.com/AdguardTeam/AdGuardHome/issues/2271
[#2297]: https://github.com/AdguardTeam/AdGuardHome/issues/2297



## [v0.104.3] - 2020-11-19

### Fixed
Expand Down
3 changes: 3 additions & 0 deletions internal/aghio/limitedreadcloser.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func (lrc *limitedReadCloser) Close() error {
// LimitReadCloser wraps ReadCloser to make it's Reader stop with
// ErrLimitReached after n bytes read.
func LimitReadCloser(rc io.ReadCloser, n int64) io.ReadCloser {
if n < 0 {
n = 0
}
return &limitedReadCloser{
limit: n,
n: n,
Expand Down
2 changes: 1 addition & 1 deletion internal/home/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func withMiddlewares(h http.Handler, middlewares ...middleware) (wrapped http.Ha
// RequestBodySizeLimit is maximum request body length in bytes.
const RequestBodySizeLimit = 64 * 1024

// LimitRequestBody wraps underlying handler h, making it's request's body Read
// limitRequestBody wraps underlying handler h, making it's request's body Read
// method limited.
func limitRequestBody(h http.Handler) (limited http.Handler) {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
8 changes: 0 additions & 8 deletions internal/update/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ func (u *Updater) GetVersionResponse(forceRecheck bool) (VersionInfo, error) {
return u.parseVersionResponse(u.versionJSON)
}

// According to godoc: When err is nil, resp always contains a non-nil
// resp.Body. Caller should close resp.Body when done reading from it.
//
// The http Client and Transport guarantee that Body is always non-nil,
// even on responses without a body or responses with a zero-length
// body. It is the caller's responsibility to close Body. The default
// HTTP client's Transport may not reuse HTTP/1.x "keep-alive" TCP
// connections if the Body is not read to completion and closed.
resp, err := u.Client.Get(u.VersionURL)
if err != nil {
return VersionInfo{}, fmt.Errorf("updater: HTTP GET %s: %w", u.VersionURL, err)
Expand Down
5 changes: 2 additions & 3 deletions internal/update/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,15 @@ func (u *Updater) clean() {
}

// MaxPackageFileSize is a maximum package file length in bytes.
const MaxPackageFileSize = 5 * 1024 * 1024
const MaxPackageFileSize = 32 * 1024 * 1024

// Download package file and save it to disk
func (u *Updater) downloadPackageFile(url string, filename string) error {
resp, err := u.Client.Get(url)
if err != nil {
return fmt.Errorf("http request failed: %w", err)
}
// According to go doc: When err is nil, resp always contains a non-nil
// resp.Body. Caller should close resp.Body when done reading from it.

resp.Body = aghio.LimitReadCloser(resp.Body, MaxPackageFileSize)
defer resp.Body.Close()

Expand Down

0 comments on commit f57a2f5

Please sign in to comment.