@@ -85,9 +85,6 @@ type httpSmartSubtransport struct {
8585}
8686
8787func (t * httpSmartSubtransport ) Action (targetUrl string , action git2go.SmartServiceAction ) (git2go.SmartSubtransportStream , error ) {
88- var req * http.Request
89- var err error
90-
9188 var proxyFn func (* http.Request ) (* url.URL , error )
9289 proxyOpts , err := t .transport .SmartProxyOptions ()
9390 if err != nil {
@@ -125,26 +122,50 @@ func (t *httpSmartSubtransport) Action(targetUrl string, action git2go.SmartServ
125122 ExpectContinueTimeout : 1 * time .Second ,
126123 }
127124
128- finalUrl := targetUrl
129- opts , found := transportOptions (targetUrl )
130- if found && opts .TargetUrl != "" {
131- // override target URL only if options are found and a new targetURL
132- // is provided.
133- finalUrl = opts .TargetUrl
125+ client , req , err := createClientRequest (targetUrl , action , httpTransport )
126+ if err != nil {
127+ return nil , err
128+ }
129+
130+ stream := newManagedHttpStream (t , req , client )
131+ if req .Method == "POST" {
132+ stream .recvReply .Add (1 )
133+ stream .sendRequestBackground ()
134134 }
135135
136- // Add any provided certificate to the http transport.
137- if len (opts .CABundle ) > 0 {
138- cap := x509 .NewCertPool ()
139- if ok := cap .AppendCertsFromPEM (opts .CABundle ); ! ok {
140- return nil , fmt .Errorf ("failed to use certificate from PEM" )
136+ return stream , nil
137+ }
138+
139+ func createClientRequest (targetUrl string , action git2go.SmartServiceAction , t * http.Transport ) (* http.Client , * http.Request , error ) {
140+ var req * http.Request
141+ var err error
142+
143+ if t == nil {
144+ return nil , nil , fmt .Errorf ("failed to create client: transport cannot be nil" )
145+ }
146+
147+ finalUrl := targetUrl
148+ opts , found := transportOptions (targetUrl )
149+ if found {
150+ if opts .TargetUrl != "" {
151+ // override target URL only if options are found and a new targetURL
152+ // is provided.
153+ finalUrl = opts .TargetUrl
141154 }
142- httpTransport .TLSClientConfig = & tls.Config {
143- RootCAs : cap ,
155+
156+ // Add any provided certificate to the http transport.
157+ if len (opts .CABundle ) > 0 {
158+ cap := x509 .NewCertPool ()
159+ if ok := cap .AppendCertsFromPEM (opts .CABundle ); ! ok {
160+ return nil , nil , fmt .Errorf ("failed to use certificate from PEM" )
161+ }
162+ t .TLSClientConfig = & tls.Config {
163+ RootCAs : cap ,
164+ }
144165 }
145166 }
146167
147- client := & http.Client {Transport : httpTransport , Timeout : fullHttpClientTimeOut }
168+ client := & http.Client {Transport : t , Timeout : fullHttpClientTimeOut }
148169
149170 switch action {
150171 case git2go .SmartServiceActionUploadpackLs :
@@ -172,18 +193,11 @@ func (t *httpSmartSubtransport) Action(targetUrl string, action git2go.SmartServ
172193 }
173194
174195 if err != nil {
175- return nil , err
196+ return nil , nil , err
176197 }
177198
178- req .Header .Set ("User-Agent" , "git/2.0 (git2go)" )
179-
180- stream := newManagedHttpStream (t , req , client )
181- if req .Method == "POST" {
182- stream .recvReply .Add (1 )
183- stream .sendRequestBackground ()
184- }
185-
186- return stream , nil
199+ req .Header .Set ("User-Agent" , "git/2.0 (flux-libgit2)" )
200+ return client , req , nil
187201}
188202
189203func (t * httpSmartSubtransport ) Close () error {
0 commit comments