Skip to content

Commit

Permalink
Add request body decompression. Add conf var that allows to delete ac…
Browse files Browse the repository at this point in the history
…cept-encoding header. Update tests.
  • Loading branch information
Nikolay Tkachenko committed Feb 10, 2023
1 parent 42705d0 commit 047c65b
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 211 deletions.
16 changes: 15 additions & 1 deletion cmd/api-firewall/internal/handlers/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ func (s *openapiWaf) openapiWafHandler(ctx *fasthttp.RequestCtx) error {
return web.RespondError(ctx, fasthttp.StatusBadRequest, nil)
}

// decode request body
requestContentEncoding := string(ctx.Request.Header.ContentEncoding())
if requestContentEncoding != "" {
req.Body, err = web.GetDecompressedRequestBody(&ctx.Request, requestContentEncoding)
if err != nil {
s.logger.WithFields(logrus.Fields{
"error": err,
"request_id": fmt.Sprintf("#%016X", ctx.ID()),
}).Error("request body decompression error")
return err
}
}

// Validate request
requestValidationInput := &openapi3filter.RequestValidationInput{
Request: &req,
Expand Down Expand Up @@ -282,7 +295,8 @@ func (s *openapiWaf) openapiWafHandler(ctx *fasthttp.RequestCtx) error {
respHeader.Set(sk, sv)
})

responseBodyReader, err := web.GetResponseBodyUncompressed(ctx)
// decode response body
responseBodyReader, err := web.GetDecompressedResponseBody(&ctx.Response, string(ctx.Response.Header.ContentEncoding()))
if err != nil {
s.logger.WithFields(logrus.Fields{
"error": err,
Expand Down
Loading

0 comments on commit 047c65b

Please sign in to comment.