Skip to content

Commit

Permalink
CCIP-4464: Add POST requests support in token data http client (#1556)
Browse files Browse the repository at this point in the history
## Motivation
[CCIP-4464](https://smartcontract-it.atlassian.net/browse/CCIP-4464)

## Solution
  • Loading branch information
NourElRashidy authored Dec 3, 2024
2 parents 8c94ed4 + d904a60 commit fa3b771
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions core/services/ocr2/plugins/ccip/tokendata/http/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ type IHttpClient interface {
type HttpClient struct {
}

func (s *HttpClient) Get(ctx context.Context, url string, timeout time.Duration) ([]byte, int, http.Header, error) {
func doRequest(ctx context.Context, url string, requestType string, requestBody io.Reader, timeout time.Duration) ([]byte, int, http.Header, error) {
// Use a timeout to guard against attestation API hanging, causing observation timeout and failing to make any progress.
timeoutCtx, cancel := context.WithTimeoutCause(ctx, timeout, tokendata.ErrTimeout)
defer cancel()
req, err := http.NewRequestWithContext(timeoutCtx, http.MethodGet, url, nil)
req, err := http.NewRequestWithContext(timeoutCtx, requestType, url, requestBody)
if err != nil {
return nil, http.StatusBadRequest, nil, err
}
Expand All @@ -50,7 +50,10 @@ func (s *HttpClient) Get(ctx context.Context, url string, timeout time.Duration)
return body, res.StatusCode, res.Header, err
}

func (s *HttpClient) Post(ctx context.Context, url string, requestData io.Reader, timeout time.Duration) ([]byte, int, http.Header, error) {
// TODO: Implement
return nil, 0, nil, nil
func (s *HttpClient) Get(ctx context.Context, url string, timeout time.Duration) ([]byte, int, http.Header, error) {
return doRequest(ctx, url, http.MethodGet, nil, timeout)
}

func (s *HttpClient) Post(ctx context.Context, url string, requestBody io.Reader, timeout time.Duration) ([]byte, int, http.Header, error) {
return doRequest(ctx, url, http.MethodPost, requestBody, timeout)
}

0 comments on commit fa3b771

Please sign in to comment.