http: set the proxy from the user-given options
This commit is contained in:
parent
50f588fcc4
commit
22da146353
27
http.go
27
http.go
|
@ -28,6 +28,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
@ -142,8 +143,32 @@ func (self *ManagedTransport) ensureClient() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
var cpopts C.git_proxy_options
|
||||||
|
if ret := C.git_transport_smart_proxy_options(&cpopts, self.owner); ret < 0 {
|
||||||
|
return MakeGitError(ret)
|
||||||
|
}
|
||||||
|
|
||||||
|
var proxyFn func(*http.Request) (*url.URL, error)
|
||||||
|
proxyOpts := proxyOptionsFromC(&cpopts)
|
||||||
|
switch proxyOpts.Type {
|
||||||
|
case ProxyTypeNone:
|
||||||
|
proxyFn = nil
|
||||||
|
case ProxyTypeAuto:
|
||||||
|
proxyFn = http.ProxyFromEnvironment
|
||||||
|
case ProxyTypeSpecified:
|
||||||
|
parsedUrl, err := url.Parse(proxyOpts.Url)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
proxyFn = http.ProxyURL(parsedUrl)
|
||||||
|
}
|
||||||
|
|
||||||
transport := &http.Transport{
|
transport := &http.Transport{
|
||||||
Proxy: http.ProxyFromEnvironment,
|
Proxy: proxyFn,
|
||||||
}
|
}
|
||||||
self.client = &http.Client{Transport: transport}
|
self.client = &http.Client{Transport: transport}
|
||||||
|
|
||||||
|
|
|
@ -141,6 +141,13 @@ type ProxyOptions struct {
|
||||||
Url string
|
Url string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func proxyOptionsFromC(copts *C.git_proxy_options) ProxyOptions {
|
||||||
|
return ProxyOptions{
|
||||||
|
Type: ProxyType(copts._type),
|
||||||
|
Url: C.GoString(copts.url),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Remote struct {
|
type Remote struct {
|
||||||
ptr *C.git_remote
|
ptr *C.git_remote
|
||||||
callbacks RemoteCallbacks
|
callbacks RemoteCallbacks
|
||||||
|
|
Loading…
Reference in New Issue