@@ -54,7 +54,7 @@ import (
5454 "net/url"
5555 "sync"
5656
57- "github.com/fluxcd/source-controller/internal/transport"
57+ pool "github.com/fluxcd/source-controller/internal/transport"
5858 git2go "github.com/libgit2/git2go/v33"
5959)
6060
@@ -72,8 +72,10 @@ func registerManagedHTTP() error {
7272}
7373
7474func httpSmartSubtransportFactory (remote * git2go.Remote , transport * git2go.Transport ) (git2go.SmartSubtransport , error ) {
75+ traceLog .Info ("[http]: httpSmartSubtransportFactory" )
7576 sst := & httpSmartSubtransport {
76- transport : transport ,
77+ transport : transport ,
78+ httpTransport : pool .NewOrIdle (nil ),
7779 }
7880
7981 return sst , nil
@@ -104,9 +106,8 @@ func (t *httpSmartSubtransport) Action(targetUrl string, action git2go.SmartServ
104106 proxyFn = http .ProxyURL (parsedUrl )
105107 }
106108
107- // reuses the http transport from a pool, or create new one on demand.
108- t .httpTransport = transport .NewOrIdle (nil )
109109 t .httpTransport .Proxy = proxyFn
110+ t .httpTransport .DisableCompression = false
110111
111112 client , req , err := createClientRequest (targetUrl , action , t .httpTransport )
112113 if err != nil {
@@ -209,10 +210,18 @@ func createClientRequest(targetUrl string, action git2go.SmartServiceAction, t *
209210}
210211
211212func (t * httpSmartSubtransport ) Close () error {
213+ traceLog .Info ("[http]: httpSmartSubtransport.Close()" )
212214 return nil
213215}
214216
215217func (t * httpSmartSubtransport ) Free () {
218+ traceLog .Info ("[http]: httpSmartSubtransport.Free()" )
219+
220+ if t .httpTransport != nil {
221+ traceLog .Info ("[http]: release http transport back to pool" )
222+ pool .Release (t .httpTransport )
223+ t .httpTransport = nil
224+ }
216225}
217226
218227type httpSmartSubtransportStream struct {
@@ -277,6 +286,8 @@ func (self *httpSmartSubtransportStream) Write(buf []byte) (int, error) {
277286
278287func (self * httpSmartSubtransportStream ) Free () {
279288 if self .resp != nil {
289+ traceLog .Info ("[http]: httpSmartSubtransportStream.Free()" )
290+
280291 // ensure body is fully processed and closed
281292 // for increased likelihood of transport reuse in HTTP/1.x.
282293 // it should not be a problem to do this more than once.
@@ -344,6 +355,7 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
344355 }
345356
346357 req .SetBasicAuth (userName , password )
358+ traceLog .Info ("[http]: new request" , "method" , req .Method , "URL" , req .URL )
347359 resp , err = self .client .Do (req )
348360 if err != nil {
349361 return err
@@ -363,6 +375,7 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
363375 return err
364376 }
365377
378+ traceLog .Info ("[http]: POST redirect" , "URL" , self .req .URL )
366379 continue
367380 }
368381
@@ -379,11 +392,6 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
379392 return fmt .Errorf ("Unhandled HTTP error %s" , resp .Status )
380393 }
381394
382- if self .owner .httpTransport != nil {
383- transport .Release (self .owner .httpTransport )
384- self .owner .httpTransport = nil
385- }
386-
387395 self .resp = resp
388396 self .sentRequest = true
389397 return nil
0 commit comments