summaryrefslogtreecommitdiff
path: root/plugins/http/handler.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-03-16 17:05:28 +0300
committerValery Piashchynski <[email protected]>2021-03-16 18:22:46 +0300
commit585a263a33fed50a0c9c2094e7009d0419b88df7 (patch)
tree1a50d648924aee912297372b4eb06783a8f05579 /plugins/http/handler.go
parente4940e1f73ca2ae4a38e7ef72176ee67fcab12e5 (diff)
🐛 fix issue with strange messages in the http body when max request
reached Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/http/handler.go')
-rw-r--r--plugins/http/handler.go19
1 files changed, 16 insertions, 3 deletions
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
+ }
}
}