Skip to content

Commit

Permalink
chore: Update HTTP Worker request handling (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjholm authored Jul 5, 2023
2 parents 3cbe4e0 + 8b3da8b commit 6b2fa80
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions core/pkg/worker/http_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,25 @@ func (h *HttpWorker) HandleTrigger(ctx context.Context, req *v1.TriggerRequest)

newHeader := http.Header{}

targetPath := targetHost.JoinPath(req.GetHttp().Path)
httpReq, err := http.NewRequest(req.GetHttp().GetMethod(), targetPath.String(), io.NopCloser(bytes.NewReader(req.Data)))
if err != nil {
return nil, err
}

for k, v := range req.GetHttp().Headers {
for _, val := range v.Value {
// Replace forwarded authorization with base authorization so the user gets the expected headers
if k == "X-Forwarded-Authorization" && newHeader["Authorization"] == nil {
k = "Authorization"
}
newHeader.Add(k, val)

httpReq.Header.Add(k, val)
}
}

targetPath := targetHost.JoinPath(req.GetHttp().Path)
// forward the request to the server
res, err := http.DefaultClient.Do(&http.Request{
Header: newHeader,
Method: req.GetHttp().GetMethod(),
URL: targetPath,
Body: io.NopCloser(bytes.NewReader(req.Data)),
})
res, err := http.DefaultClient.Do(httpReq)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 6b2fa80

Please sign in to comment.