8000 feat(sdk): new httpSSEClient (#3434) · ovh/cds@d47187a · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit d47187a

Browse files
authored
feat(sdk): new httpSSEClient (#3434)
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
1 parent dee449b commit d47187a

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

sdk/cdsclient/client.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import (
1212
)
1313

1414
type client struct {
15-
isWorker bool
16-
isService bool
17-
isProvider bool
18-
HTTPClient HTTPClient
19 10000 -
config Config
20-
name string
21-
service *sdk.Service
15+
isWorker bool
16+
isService bool
17+
isProvider bool
18+
HTTPClient HTTPClient
19+
HTTPSSEClient HTTPClient
20+
config Config
21+
name string
22+
service *sdk.Service
2223
}
2324

2425
// NewHTTPClient returns a new HTTP Client
@@ -46,6 +47,7 @@ func New(c Config) Interface {
4647
cli := new(client)
4748
cli.config = c
4849
cli.HTTPClient = NewHTTPClient(time.Second*60, c.InsecureSkipVerifyTLS)
50+
cli.HTTPSSEClient = NewHTTPClient(0, c.InsecureSkipVerifyTLS)
4951
cli.init()
5052
return cli
5153
}
@@ -60,6 +62,7 @@ func NewService(endpoint string, timeout time.Duration, insecureSkipVerifyTLS bo
6062
cli := new(client)
6163
cli.config = conf
6264
cli.HTTPClient = NewHTTPClient(timeout, conf.InsecureSkipVerifyTLS)
65+
cli.HTTPSSEClient = NewHTTPClient(0, conf.InsecureSkipVerifyTLS)
6366
cli.isService = true
6467
cli.init()
6568
return cli
@@ -79,6 +82,7 @@ func NewWorker(endpoint string, name string, c HTTPClient) Interface {
7982
} else {
8083
cli.HTTPClient = c
8184
}
85+
cli.HTTPSSEClient = NewHTTPClient(0, false)
8286

8387
cli.isWorker = true
8488
cli.name = name
@@ -112,6 +116,7 @@ func NewProviderClient(cfg ProviderConfig) ProviderClient {
112116
cli := new(client)
113117
cli.config = conf
114118
cli.HTTPClient = NewHTTPClient(time.Duration(cfg.RequestSecondsTimeout)*time.Second, conf.InsecureSkipVerifyTLS)
119+
cli.HTTPSSEClient = NewHTTPClient(0, conf.InsecureSkipVerifyTLS)
115120
cli.isProvider = true
116121
cli.name = cfg.Name
117122
cli.init()

sdk/cdsclient/http.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ type HTTPClient interface {
4949
Do(*http.Request) (*http.Response, error)
5050
}
5151

52-
// NoTimeout returns a http.DefaultClient from a HTTPClient
53-
func NoTimeout(c HTTPClient) HTTPClient {
54-
return http.DefaultClient
55-
}
56-
5752
// SetHeader modify headers of http.Request
5853
func SetHeader(key, value string) RequestModifier {
5954
return func(req *http.Request) {
@@ -243,7 +238,7 @@ func (c *client) Stream(ctx context.Context, method string, path string, body io
243238
var errDo error
244239
var resp *http.Response
245240
if noTimeout {
246< D5CB /code>-
resp, errDo = NoTimeout(c.HTTPClient).Do(req)
241+
resp, errDo = c.HTTPSSEClient.Do(req)
247242
} else {
248243
resp, errDo = c.HTTPClient.Do(req)
249244
}
@@ -334,7 +329,7 @@ func (c *client) UploadMultiPart(method string, path string, body *bytes.Buffer,
334329
}
335330
}
336331

337-
resp, err := NoTimeout(c.HTTPClient).Do(req)
332+
resp, err := c.HTTPSSEClient.Do(req)
338333
if err != nil {
339334
return nil, 0, err
340335
}

sdk/cdsclient/http_sse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (c *client) RequestSSEGet(ctx context.Context, path string, evCh chan<- SSE
6464
req.SetBasicAuth(c.config.User, c.config.Token)
6565
}
6666

67-
resp, err := NoTimeout(c.HTTPClient).Do(req)
67+
resp, err := c.HTTPSSEClient.Do(req)
6868
if err != nil {
6969
return err
7070
}

0 commit comments

Comments
 (0)
0