Skip to content

Commit

Permalink
Add POST requests support in token data http client
Browse files Browse the repository at this point in the history
  • Loading branch information
NourElRashidy committed Dec 2, 2024
1 parent 8c94ed4 commit d904a60
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 d904a60

Please sign in to comment.