@@ -85,9 +85,6 @@ type httpSmartSubtransport struct {
85
85
}
86
86
87
87
func (t * httpSmartSubtransport ) Action (targetUrl string , action git2go.SmartServiceAction ) (git2go.SmartSubtransportStream , error ) {
88
- var req * http.Request
89
- var err error
90
-
91
88
var proxyFn func (* http.Request ) (* url.URL , error )
92
89
proxyOpts , err := t .transport .SmartProxyOptions ()
93
90
if err != nil {
@@ -125,26 +122,50 @@ func (t *httpSmartSubtransport) Action(targetUrl string, action git2go.SmartServ
125
122
ExpectContinueTimeout : 1 * time .Second ,
126
123
}
127
124
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 ()
134
134
}
135
135
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
141
154
}
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
+ }
144
165
}
145
166
}
146
167
147
- client := & http.Client {Transport : httpTransport , Timeout : fullHttpClientTimeOut }
168
+ client := & http.Client {Transport : t , Timeout : fullHttpClientTimeOut }
148
169
149
170
switch action {
150
171
case git2go .SmartServiceActionUploadpackLs :
@@ -172,18 +193,11 @@ func (t *httpSmartSubtransport) Action(targetUrl string, action git2go.SmartServ
172
193
}
173
194
174
195
if err != nil {
175
- return nil , err
196
+ return nil , nil , err
176
197
}
177
198
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
187
201
}
188
202
189
203
func (t * httpSmartSubtransport ) Close () error {
0 commit comments