From c726f932dbe2f52deca64183d3dffea6a3c86384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 17 Apr 2017 12:44:28 +0200 Subject: [PATCH] http: use an environment-provided proxy We currently cannot ask the transport for its proxy settings, so for now we'll use the one from the environment. --- http.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/http.go b/http.go index c32fc18..b790849 100644 --- a/http.go +++ b/http.go @@ -82,9 +82,17 @@ func RegisterManagedHttps() error { return nil } -type ManagedTransport struct{} +type ManagedTransport struct { + owner *C.git_transport + + client *http.Client +} func (self *ManagedTransport) Action(url string, action SmartService) (SmartSubtransportStream, error) { + if err := self.ensureClient(); err != nil { + return nil, err + } + var req *http.Request var err error switch action { @@ -128,6 +136,19 @@ func (self *ManagedTransport) Close() error { func (self *ManagedTransport) Free() { } +func (self *ManagedTransport) ensureClient() error { + if self.client != nil { + return nil + } + + transport := &http.Transport{ + Proxy: http.ProxyFromEnvironment, + } + self.client = &http.Client{Transport: transport} + + return nil +} + type ManagedHttpStream struct { req *http.Request resp *http.Response @@ -247,7 +268,7 @@ func httpSmartSubtransportCb(out **C.git_smart_subtransport, owner *C.git_transp } transport := C.calloc(1, C.size_t(unsafe.Sizeof(C.managed_smart_subtransport{}))) - managed := &ManagedTransport{} + managed := &ManagedTransport{owner: owner} managedPtr := pointerHandles.Track(managed) C._go_git_setup_smart_subtransport(transport, managedPtr)