Skip to content

Commit

Permalink
home: imp names
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Feb 15, 2021
1 parent dad39ae commit 2b45c9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions internal/home/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ func withMiddlewares(h http.Handler, middlewares ...middleware) (wrapped http.Ha
return wrapped
}

// RequestBodySizeLimit is the maximum request body size in bytes.
const RequestBodySizeLimit = 64 * 1024
// defaultReqBodySzLim is the default maximum request body size.
const defaultReqBodySzLim = 64 * 1024

// largerRequestBodySizeLimit is the maximum request body size for APIs
// expecting larger requests.
const largerRequestBodySizeLimit = 4 * 1024 * 1024
// largerReqBodySzLim is the maximum request body size for APIs expecting larger
// requests.
const largerReqBodySzLim = 4 * 1024 * 1024

// expectsLargerRequests shows if this request should use a larger body size
// limit. These are exceptions for poorly designed current APIs as well as APIs
Expand All @@ -53,9 +53,9 @@ func limitRequestBody(h http.Handler) (limited http.Handler) {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var err error

var szLim int64 = RequestBodySizeLimit
var szLim int64 = defaultReqBodySzLim
if expectsLargerRequests(r) {
szLim = largerRequestBodySizeLimit
szLim = largerReqBodySzLim
}

r.Body, err = aghio.LimitReadCloser(r.Body, szLim)
Expand Down
6 changes: 3 additions & 3 deletions internal/home/middlewares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestLimitRequestBody(t *testing.T) {
errReqLimitReached := &aghio.LimitReachedError{
Limit: RequestBodySizeLimit,
Limit: defaultReqBodySzLim,
}

testCases := []struct {
Expand All @@ -29,8 +29,8 @@ func TestLimitRequestBody(t *testing.T) {
wantErr: nil,
}, {
name: "so_big",
body: string(make([]byte, RequestBodySizeLimit+1)),
want: make([]byte, RequestBodySizeLimit),
body: string(make([]byte, defaultReqBodySzLim+1)),
want: make([]byte, defaultReqBodySzLim),
wantErr: errReqLimitReached,
}, {
name: "empty",
Expand Down

0 comments on commit 2b45c9b

Please sign in to comment.