diff options
author | Igor Drozdov <idrozdov@gitlab.com> | 2019-04-23 14:07:38 +0300 |
---|---|---|
committer | Igor Drozdov <idrozdov@gitlab.com> | 2019-04-23 14:23:31 +0300 |
commit | fbaba66e124441d0e283fd4e2966d7af790ce23a (patch) | |
tree | b7560b534f9290b4f9b341f956c22d10d7db95dc /go/internal/gitlabnet/httpclient.go | |
parent | 9ed567b6fd14ef389df11b46be3022a90eda68ec (diff) | |
download | gitlab-shell-id-api-regular-http.tar.gz |
Move http client building to configid-api-regular-http
Diffstat (limited to 'go/internal/gitlabnet/httpclient.go')
-rw-r--r-- | go/internal/gitlabnet/httpclient.go | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/go/internal/gitlabnet/httpclient.go b/go/internal/gitlabnet/httpclient.go deleted file mode 100644 index de40051..0000000 --- a/go/internal/gitlabnet/httpclient.go +++ /dev/null @@ -1,69 +0,0 @@ -package gitlabnet - -import ( - "context" - "net" - "net/http" - "strings" - - "gitlab.com/gitlab-org/gitlab-shell/go/internal/config" -) - -const ( - socketBaseUrl = "http://unix" - UnixSocketProtocol = "http+unix://" - HttpProtocol = "http://" -) - -type GitlabHttpClient struct { - httpClient *http.Client - config *config.Config - host string -} - -func buildSocketClient(config *config.Config) *GitlabHttpClient { - path := strings.TrimPrefix(config.GitlabUrl, UnixSocketProtocol) - transport := &http.Transport{ - DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) { - dialer := net.Dialer{} - return dialer.DialContext(ctx, "unix", path) - }, - } - - return buildClient(config, transport, socketBaseUrl) -} - -func buildHttpClient(config *config.Config) *GitlabHttpClient { - return buildClient(config, &http.Transport{}, config.GitlabUrl) -} - -func buildClient(config *config.Config, transport *http.Transport, host string) *GitlabHttpClient { - httpClient := &http.Client{ - Transport: transport, - Timeout: config.HttpSettings.ReadTimeout(), - } - - return &GitlabHttpClient{httpClient: httpClient, config: config, host: host} -} - -func (c *GitlabHttpClient) Get(path string) (*http.Response, error) { - return c.doRequest("GET", path, nil) -} - -func (c *GitlabHttpClient) Post(path string, data interface{}) (*http.Response, error) { - return c.doRequest("POST", path, data) -} - -func (c *GitlabHttpClient) doRequest(method, path string, data interface{}) (*http.Response, error) { - request, err := newRequest(method, c.host, path, data) - if err != nil { - return nil, err - } - - user, password := c.config.HttpSettings.User, c.config.HttpSettings.Password - if user != "" && password != "" { - request.SetBasicAuth(user, password) - } - - return doRequest(c.httpClient, c.config, request) -} |