diff options
-rw-r--r-- | .github/workflows/linux.yml | 2 | ||||
-rwxr-xr-x | Makefile | 8 | ||||
-rw-r--r-- | plugins/http/handler.go | 19 | ||||
-rw-r--r-- | tests/plugins/checker/plugin_test.go | 2 |
4 files changed, 22 insertions, 9 deletions
diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 00057e38..c5fde431 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -74,7 +74,7 @@ jobs: go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/informer.txt -covermode=atomic ./tests/plugins/informer go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/reload.txt -covermode=atomic ./tests/plugins/reload go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/server.txt -covermode=atomic ./tests/plugins/server - go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/checker.txt -covermode=atomic ./tests/plugins/checker + go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/status.txt -covermode=atomic ./tests/plugins/status go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/config.txt -covermode=atomic ./tests/plugins/config go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/gzip.txt -covermode=atomic ./tests/plugins/gzip go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/headers.txt -covermode=atomic ./tests/plugins/headers @@ -36,7 +36,7 @@ test_coverage: go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/informer.out -covermode=atomic ./tests/plugins/informer go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/reload.out -covermode=atomic ./tests/plugins/reload go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/server.out -covermode=atomic ./tests/plugins/server - go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/checker.out -covermode=atomic ./tests/plugins/checker + go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/status.out -covermode=atomic ./tests/plugins/status go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/config.out -covermode=atomic ./tests/plugins/config go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/gzip.out -covermode=atomic ./tests/plugins/gzip go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/headers.out -covermode=atomic ./tests/plugins/headers @@ -68,7 +68,7 @@ test: ## Run application tests go test -v -race -tags=debug ./tests/plugins/informer go test -v -race -tags=debug ./tests/plugins/reload go test -v -race -tags=debug ./tests/plugins/server - go test -v -race -tags=debug ./tests/plugins/checker + go test -v -race -tags=debug ./tests/plugins/status go test -v -race -tags=debug ./tests/plugins/config go test -v -race -tags=debug ./tests/plugins/gzip go test -v -race -tags=debug ./tests/plugins/headers @@ -98,7 +98,7 @@ test_1.14: ## Run application tests go1.14.14 test -v -race -tags=debug ./tests/plugins/informer go1.14.14 test -v -race -tags=debug ./tests/plugins/reload go1.14.14 test -v -race -tags=debug ./tests/plugins/server - go1.14.14 test -v -race -tags=debug ./tests/plugins/checker + go1.14.14 test -v -race -tags=debug ./tests/plugins/status go1.14.14 test -v -race -tags=debug ./tests/plugins/config go1.14.14 test -v -race -tags=debug ./tests/plugins/gzip go1.14.14 test -v -race -tags=debug ./tests/plugins/headers @@ -128,7 +128,7 @@ test_1.16: ## Run application tests go1.16rc1 test -v -race -tags=debug ./tests/plugins/informer go1.16rc1 test -v -race -tags=debug ./tests/plugins/reload go1.16rc1 test -v -race -tags=debug ./tests/plugins/server - go1.16rc1 test -v -race -tags=debug ./tests/plugins/checker + go1.16rc1 test -v -race -tags=debug ./tests/plugins/status go1.16rc1 test -v -race -tags=debug ./tests/plugins/config go1.16rc1 test -v -race -tags=debug ./tests/plugins/gzip go1.16rc1 test -v -race -tags=debug ./tests/plugins/headers diff --git a/plugins/http/handler.go b/plugins/http/handler.go index 0e7481b5..327d8aea 100644 --- a/plugins/http/handler.go +++ b/plugins/http/handler.go @@ -95,9 +95,22 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // validating request size if h.maxRequestSize != 0 { - err := h.maxSize(w, r, start, op) - if err != nil { - return + const op = errors.Op("http_handler_max_size") + if length := r.Header.Get("content-length"); length != "" { + // try to parse the value from the `content-length` header + size, err := strconv.ParseInt(length, 10, 64) + if err != nil { + // if got an error while parsing -> assign 500 code to the writer and return + http.Error(w, errors.E(op, err).Error(), 500) + h.sendEvent(ErrorEvent{Request: r, Error: errors.E(op, errors.Str("error while parsing value from the `content-length` header")), start: start, elapsed: time.Since(start)}) + return + } + + if size > int64(h.maxRequestSize) { + h.sendEvent(ErrorEvent{Request: r, Error: errors.E(op, errors.Str("request body max size is exceeded")), start: start, elapsed: time.Since(start)}) + http.Error(w, errors.E(op, errors.Str("request body max size is exceeded")).Error(), 500) + return + } } } diff --git a/tests/plugins/checker/plugin_test.go b/tests/plugins/checker/plugin_test.go index 569e73a1..251ab877 100644 --- a/tests/plugins/checker/plugin_test.go +++ b/tests/plugins/checker/plugin_test.go @@ -114,7 +114,7 @@ func TestStatusRPC(t *testing.T) { assert.NoError(t, err) cfg := &config.Viper{ - Path: "configs/.rr-checker-init.yaml", + Path: "configs/.rr-status-init.yaml", Prefix: "rr", } |