diff options
author | Sanskar Jaiswal <jaiswalsanskar078@gmail.com> | 2023-04-13 12:49:53 +0530 |
---|---|---|
committer | Sanskar Jaiswal <jaiswalsanskar078@gmail.com> | 2023-05-04 11:53:09 +0530 |
commit | c2a93140c4d2a7df5666c7e436d8f1cb337a579d (patch) | |
tree | 60e534a7115b8a675c2ed4b39c8219643622b023 /plumbing/transport | |
parent | da73c5f950fb399611e3eb608f6ee99f23eb53b5 (diff) | |
download | go-git-c2a93140c4d2a7df5666c7e436d8f1cb337a579d.tar.gz |
plumbing/transport: add ProxyOptions to specify proxy details
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
Diffstat (limited to 'plumbing/transport')
-rw-r--r-- | plumbing/transport/common.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/plumbing/transport/common.go b/plumbing/transport/common.go index a2a78f0..89bd3d5 100644 --- a/plumbing/transport/common.go +++ b/plumbing/transport/common.go @@ -116,6 +116,37 @@ type Endpoint struct { InsecureSkipTLS bool // CaBundle specify additional ca bundle with system cert pool CaBundle []byte + // Proxy provides info required for connecting to a proxy. + Proxy ProxyOptions +} + +type ProxyOptions struct { + URL string + Username string + Password string +} + +func (o *ProxyOptions) Validate() error { + if o.URL != "" { + _, err := url.Parse(o.URL) + return err + } + return nil +} + +func (o *ProxyOptions) FullURL() (*url.URL, error) { + proxyURL, err := url.Parse(o.URL) + if err != nil { + return nil, err + } + if o.Username != "" { + if o.Password != "" { + proxyURL.User = url.UserPassword(o.Username, o.Password) + } else { + proxyURL.User = url.User(o.Username) + } + } + return proxyURL, nil } var defaultPorts = map[string]int{ |