blob: 40b9a8fbe00a78bab967a206bd47698704012084 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package util
import (
"crypto/tls"
"net/http"
"time"
)
type HTTPClient interface {
Do(request *http.Request, timeout time.Duration) (response *http.Response, error error)
UseCertificate(certificate []tls.Certificate)
}
type defaultHttpClient struct {
client *http.Client
}
func (c *defaultHttpClient) Do(request *http.Request, timeout time.Duration) (response *http.Response, error error) {
if c.client.Timeout != timeout { // Set wanted timeout
c.client.Timeout = timeout
}
return c.client.Do(request)
}
func (c *defaultHttpClient) UseCertificate(certificates []tls.Certificate) {
c.client.Transport = &http.Transport{TLSClientConfig: &tls.Config{
Certificates: certificates,
}}
}
func CreateClient(timeout time.Duration) HTTPClient {
return &defaultHttpClient{client: &http.Client{Timeout: timeout}}
}
|