Skip to content

Commit

Permalink
fix: set request in hook context before send request, in case of error
Browse files Browse the repository at this point in the history
  • Loading branch information
df-wg committed Dec 15, 2024
1 parent 2d960bf commit 0d89e73
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions v2/pkg/engine/datasource/httpclient/nethttpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func InjectResponseContext(ctx context.Context) (context.Context, *ResponseConte
return context.WithValue(ctx, responseContextKey{}, value), value
}

func setRequest(ctx context.Context, request *http.Request) {
if value, ok := ctx.Value(responseContextKey{}).(*ResponseContext); ok {
value.Request = request
}
}

func setResponseStatus(ctx context.Context, request *http.Request, response *http.Response) {
if value, ok := ctx.Value(responseContextKey{}).(*ResponseContext); ok {
value.StatusCode = response.StatusCode
Expand Down Expand Up @@ -189,6 +195,8 @@ func makeHTTPRequest(client *http.Client, ctx context.Context, url, method, head
request.Header.Set(AcceptEncodingHeader, EncodingGzip)
request.Header.Add(AcceptEncodingHeader, EncodingDeflate)

setRequest(ctx, request)

response, err := client.Do(request)
if err != nil {
return err
Expand Down

0 comments on commit 0d89e73

Please sign in to comment.