forked from opensearch-project/opensearch-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
49 lines (41 loc) · 1.08 KB
/
http.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
package client
import (
"crypto/tls"
"net/http"
"time"
"github.com/hashicorp/go-retryablehttp"
)
const defaultTimeout = 10
//Client is an Abstraction for actual client
type Client struct {
HTTPClient *retryablehttp.Client
}
//NewDefaultClient return new instance of client
func NewDefaultClient(tripper http.RoundTripper) (*Client, error) {
client := retryablehttp.NewClient()
client.HTTPClient.Transport = tripper
client.HTTPClient.Timeout = defaultTimeout * time.Second
client.Logger = nil
return &Client{
HTTPClient: client,
}, nil
}
//New takes transport and uses accordingly
func New(tripper http.RoundTripper) (*Client, error) {
if tripper == nil {
tripper = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
}
return NewDefaultClient(tripper)
}