From f959e79b48c59138b5db5e0e87d7aa124f2e38ad Mon Sep 17 00:00:00 2001 From: Guillem Nieto Date: Wed, 27 Apr 2022 08:47:11 +0200 Subject: [PATCH] Change parser to forward all headers Previous to this changes, only the relevant headers for the hook were forwarded. Right now, we are keeping all of them and then we are checking that, required headers, are present. This should prevent removing the github signature when the proxy does not validate the request signature. --- pkg/parser/parser.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index 3db2201..e4b3806 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -14,11 +14,17 @@ func Parse(req *http.Request, provider providers.Provider) (*providers.Hook, err } for _, header := range provider.GetHeaderKeys() { - if req.Header.Get(header) != "" { - hook.Headers[header] = req.Header.Get(header) - continue + if req.Header.Get(header) == "" { + return nil, errors.New("Required header '" + header + "' not found in Request") } - return nil, errors.New("Required header '" + header + "' not found in Request") + + // Store required headers in the expected casing + hook.Headers[header] = req.Header.Get(header) + } + + for header := range req.Header { + // Store the rest of the headers in any casing + hook.Headers[header] = req.Header.Get(header) } if body, err := ioutil.ReadAll(req.Body); err != nil {