Skip to content

Commit

Permalink
Removed executor thing, it had no value because we don't use the mock
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeker12 committed Feb 28, 2025
1 parent 74c575b commit 8804914
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 134 deletions.
31 changes: 5 additions & 26 deletions httpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,19 @@ package httpclient

import (
"fmt"
"io"
"net/http"
"net/http/cookiejar"
"net/url"
"time"

"github.com/deploymenttheory/go-api-http-client/concurrency"
"go.uber.org/zap"
)

// HTTPExecutor is an interface which wraps http.Client to allow mocking.
type HTTPExecutor interface {

// Inherited
CloseIdleConnections()
Do(req *http.Request) (*http.Response, error)
Get(url string) (resp *http.Response, err error)
Head(url string) (resp *http.Response, err error)
Post(url string, contentType string, body io.Reader) (resp *http.Response, err error)
PostForm(url string, data url.Values) (resp *http.Response, err error)

// Additional
SetCookieJar(jar http.CookieJar)
SetCookies(url *url.URL, cookies []*http.Cookie)
SetCustomTimeout(time.Duration)
Cookies(*url.URL) []*http.Cookie
SetRedirectPolicy(*func(req *http.Request, via []*http.Request) error)
}

// Master struct/object
type Client struct {
config *ClientConfig
Integration *APIIntegration
http HTTPExecutor
http *http.Client
Sugar *zap.SugaredLogger
Concurrency *concurrency.ConcurrencyHandler
}
Expand Down Expand Up @@ -100,7 +79,7 @@ type ClientConfig struct {
// RetryEligiableRequests when false bypasses any retry logic for a simpler request flow.
RetryEligiableRequests bool `json:"retry_eligiable_requests"`

HTTPExecutor HTTPExecutor
HTTPExecutor http.Client
}

// BuildClient creates a new HTTP client with the provided configuration.
Expand Down Expand Up @@ -131,10 +110,10 @@ func (c *ClientConfig) Build() (*Client, error) {
return nil, err
}

httpClient.SetCookieJar(cookieJar)
httpClient.Jar = cookieJar

if c.CustomRedirectPolicy != nil {
httpClient.SetRedirectPolicy(c.CustomRedirectPolicy)
httpClient.CheckRedirect = *c.CustomRedirectPolicy
}

// TODO refactor concurrency
Expand All @@ -150,7 +129,7 @@ func (c *ClientConfig) Build() (*Client, error) {

client := &Client{
Integration: &c.Integration,
http: httpClient,
http: &httpClient,
config: c,
Sugar: c.Sugar,
Concurrency: concurrencyHandler,
Expand Down
4 changes: 2 additions & 2 deletions httpclient/cookies.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ func (c *Client) loadCustomCookies() error {
return err
}

c.http.SetCookies(cookieUrl, c.config.CustomCookies)
c.http.Jar.SetCookies(cookieUrl, c.config.CustomCookies)

if c.config.HideSensitiveData {
c.Sugar.Debug("[REDACTED] cookies set successfully")
} else {
c.Sugar.Debug("custom cookies set: %v", c.http.Cookies(cookieUrl))
c.Sugar.Debug("custom cookies set: %v", c.http.Jar.Cookies(cookieUrl))
}

return nil
Expand Down
106 changes: 0 additions & 106 deletions httpclient/http.go

This file was deleted.

0 comments on commit 8804914

Please sign in to comment.