5
5
package proxy
6
6
7
7
import (
8
+ "crypto/tls"
8
9
"fmt"
9
10
"net"
10
11
"net/http"
@@ -37,6 +38,9 @@ func (ppc *proxyPassConfig) appendResponseHandler(handler responseHandler) {
37
38
// proxyPassOpt allows to compose ProxyHandler options.
38
39
type proxyPassOpt func (h * proxyPassConfig )
39
40
41
+ // createHttpTransportOpt allows to compose create http Transport options.
42
+ type createHttpTransportOpt func (h * http.Transport )
43
+
40
44
// errorHandler is a function that handles an error that occurred during proxying of a HTTP request.
41
45
type errorHandler func (http.ResponseWriter , * http.Request , error )
42
46
@@ -218,10 +222,16 @@ func withErrorHandler(h errorHandler) proxyPassOpt {
218
222
}
219
223
}
220
224
221
- func createDefaultTransport (config * TransportConfig ) http.RoundTripper {
222
- // TODO equivalent of client_max_body_size 2048m; necessary ???
223
- // this is based on http.DefaultTransport, with some values exposed to config
224
- return instrumentClientMetrics (& http.Transport {
225
+ func withSkipTLSVerify () createHttpTransportOpt {
226
+ return func (tr * http.Transport ) {
227
+ tr .TLSClientConfig = & tls.Config {
228
+ InsecureSkipVerify : true ,
229
+ }
230
+ }
231
+ }
232
+
233
+ func createDefaultTransport (config * TransportConfig , opts ... createHttpTransportOpt ) http.RoundTripper {
234
+ transport := & http.Transport {
225
235
Proxy : http .ProxyFromEnvironment ,
226
236
DialContext : (& net.Dialer {
227
237
Timeout : time .Duration (config .ConnectTimeout ), // default: 30s
@@ -234,7 +244,13 @@ func createDefaultTransport(config *TransportConfig) http.RoundTripper {
234
244
IdleConnTimeout : time .Duration (config .IdleConnTimeout ), // default: 90s
235
245
TLSHandshakeTimeout : 10 * time .Second ,
236
246
ExpectContinueTimeout : 1 * time .Second ,
237
- })
247
+ }
248
+ for _ , o := range opts {
249
+ o (transport )
250
+ }
251
+ // TODO equivalent of client_max_body_size 2048m; necessary ???
252
+ // this is based on http.DefaultTransport, with some values exposed to config
253
+ return instrumentClientMetrics (transport )
238
254
}
239
255
240
256
// tell the browser to cache for 1 year and don't ask the server during this period.
0 commit comments