Skip to content

Commit

Permalink
Merge pull request #10 from StephanHCB/feature/allow-getting-raw-body
Browse files Browse the repository at this point in the history
#9 - allow access to raw byte slice of response
  • Loading branch information
StephanHCB committed Oct 17, 2022
2 parents 995530d + ad6f426 commit 86fa277
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions implementation/httpclient/httpclient.go
Expand Up @@ -148,10 +148,15 @@ func (c *HttpClientImpl) Perform(ctx context.Context, method string, requestUrl
}

if len(responseBody) > 0 && response.Body != nil {
err := json.Unmarshal(responseBody, response.Body)
if err != nil {
c.ResponseMetricsCallback(ctx, method, requestUrl, response.Status, err, c.Now().Sub(response.Time), len(responseBody))
return aurestnontripping.New(ctx, err)
switch response.Body.(type) {
case **[]byte:
*(response.Body.(**[]byte)) = &responseBody
default:
err := json.Unmarshal(responseBody, response.Body)
if err != nil {
c.ResponseMetricsCallback(ctx, method, requestUrl, response.Status, err, c.Now().Sub(response.Time), len(responseBody))
return aurestnontripping.New(ctx, err)
}
}
c.ResponseMetricsCallback(ctx, method, requestUrl, response.Status, nil, c.Now().Sub(response.Time), len(responseBody))
} else {
Expand Down

0 comments on commit 86fa277

Please sign in to comment.