Skip to content

Commit

Permalink
feat(sdk): new httpSSEClient (#3434)
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
  • Loading branch information
yesnault committed Oct 10, 2018
1 parent dee449b commit d47187a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
19 changes: 12 additions & 7 deletions sdk/cdsclient/client.go
Expand Up @@ -12,13 +12,14 @@ import (
)

type client struct {
isWorker bool
isService bool
isProvider bool
HTTPClient HTTPClient
config Config
name string
service *sdk.Service
isWorker bool
isService bool
isProvider bool
HTTPClient HTTPClient
HTTPSSEClient HTTPClient
config Config
name string
service *sdk.Service
}

// NewHTTPClient returns a new HTTP Client
Expand Down Expand Up @@ -46,6 +47,7 @@ func New(c Config) Interface {
cli := new(client)
cli.config = c
cli.HTTPClient = NewHTTPClient(time.Second*60, c.InsecureSkipVerifyTLS)
cli.HTTPSSEClient = NewHTTPClient(0, c.InsecureSkipVerifyTLS)
cli.init()
return cli
}
Expand All @@ -60,6 +62,7 @@ func NewService(endpoint string, timeout time.Duration, insecureSkipVerifyTLS bo
cli := new(client)
cli.config = conf
cli.HTTPClient = NewHTTPClient(timeout, conf.InsecureSkipVerifyTLS)
cli.HTTPSSEClient = NewHTTPClient(0, conf.InsecureSkipVerifyTLS)
cli.isService = true
cli.init()
return cli
Expand All @@ -79,6 +82,7 @@ func NewWorker(endpoint string, name string, c HTTPClient) Interface {
} else {
cli.HTTPClient = c
}
cli.HTTPSSEClient = NewHTTPClient(0, false)

cli.isWorker = true
cli.name = name
Expand Down Expand Up @@ -112,6 +116,7 @@ func NewProviderClient(cfg ProviderConfig) ProviderClient {
cli := new(client)
cli.config = conf
cli.HTTPClient = NewHTTPClient(time.Duration(cfg.RequestSecondsTimeout)*time.Second, conf.InsecureSkipVerifyTLS)
cli.HTTPSSEClient = NewHTTPClient(0, conf.InsecureSkipVerifyTLS)
cli.isProvider = true
cli.name = cfg.Name
cli.init()
Expand Down
9 changes: 2 additions & 7 deletions sdk/cdsclient/http.go
Expand Up @@ -49,11 +49,6 @@ type HTTPClient interface {
Do(*http.Request) (*http.Response, error)
}

// NoTimeout returns a http.DefaultClient from a HTTPClient
func NoTimeout(c HTTPClient) HTTPClient {
return http.DefaultClient
}

// SetHeader modify headers of http.Request
func SetHeader(key, value string) RequestModifier {
return func(req *http.Request) {
Expand Down Expand Up @@ -243,7 +238,7 @@ func (c *client) Stream(ctx context.Context, method string, path string, body io
var errDo error
var resp *http.Response
if noTimeout {
resp, errDo = NoTimeout(c.HTTPClient).Do(req)
resp, errDo = c.HTTPSSEClient.Do(req)
} else {
resp, errDo = c.HTTPClient.Do(req)
}
Expand Down Expand Up @@ -334,7 +329,7 @@ func (c *client) UploadMultiPart(method string, path string, body *bytes.Buffer,
}
}

resp, err := NoTimeout(c.HTTPClient).Do(req)
resp, err := c.HTTPSSEClient.Do(req)
if err != nil {
return nil, 0, err
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/cdsclient/http_sse.go
Expand Up @@ -64,7 +64,7 @@ func (c *client) RequestSSEGet(ctx context.Context, path string, evCh chan<- SSE
req.SetBasicAuth(c.config.User, c.config.Token)
}

resp, err := NoTimeout(c.HTTPClient).Do(req)
resp, err := c.HTTPSSEClient.Do(req)
if err != nil {
return err
}
Expand Down

0 comments on commit d47187a

Please sign in to comment.