Skip to content

Commit

Permalink
Merge pull request #5 from madebymode/patch
Browse files Browse the repository at this point in the history
Minor Patch: better errors/handling
  • Loading branch information
troyxmccall authored Jul 29, 2023
2 parents 2ae555d + b3aba69 commit 743a92a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 0 additions & 2 deletions .traefik.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ testData:
CacheKeyIncludeRequestURI: true
CacheKeyIncludeHeaders: false
CacheKeyHeaders:
- Authorization
- User-Agent
- Cache-Control
CacheKeyMatchAllHeaders: false
CacheKeyIncludeHost: true
CacheKeyIncludeRemoteAddress: false


iconPath: ./img/icon.png
bannerPath: ./img/banner.png
2 changes: 2 additions & 0 deletions modsecurity.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ func (a *Modsecurity) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
resp, respErr := a.HandleCacheAndForwardRequest(reqCopy)

if respErr != nil {
a.logger.Printf("error handling request: %v", respErr)
http.Error(rw, "Internal Server Error", http.StatusInternalServerError)
return
}

Expand Down
5 changes: 3 additions & 2 deletions modsecurity_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package traefik_modsecurity_plugin

import (
"bytes"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -16,10 +17,10 @@ func (a *Modsecurity) HandleRequestBodyMaxSize(rw http.ResponseWriter, req *http
bodyReader := io.LimitReader(req.Body, a.maxBodySize+1)
bodyBuffer := new(bytes.Buffer)
n, err := io.Copy(bodyBuffer, bodyReader)
req.Body.Close()
err = req.Body.Close()

if err != nil {
if err == io.EOF || err == io.ErrUnexpectedEOF {
if err == io.EOF || errors.Is(err, io.ErrUnexpectedEOF) {
// Request body size is within limit.
req.Body = io.NopCloser(bodyBuffer)
return nil
Expand Down

0 comments on commit 743a92a

Please sign in to comment.