@@ -9,9 +9,11 @@ import (
9
9
"io"
10
10
"mime"
11
11
"mime/multipart"
12
+ "net"
12
13
"net/http"
13
14
"net/url"
14
15
"strings"
16
+ "time"
15
17
)
16
18
17
19
// RequestOptions is the location that of where the data
@@ -79,8 +81,15 @@ func buildRequest(httpMethod, url string, ro *RequestOptions) (*http.Response, e
79
81
httpClient := buildHTTPClient (ro )
80
82
81
83
// Build our URL
84
+ var err error
85
+
82
86
if ro .Params != nil {
83
- url = buildURLParams (url , ro .Params )
87
+ url , err = buildURLParams (url , ro .Params )
88
+
89
+ if err != nil {
90
+ return nil , err
91
+ }
92
+
84
93
}
85
94
86
95
// Build the request
@@ -232,23 +241,35 @@ func encodePostValues(postValues map[string]string) string {
232
241
}
233
242
234
243
func buildHTTPClient (ro * RequestOptions ) * http.Client {
244
+ if ro .InsecureSkipVerify != true && ro .DisableCompression != true {
245
+ return http .DefaultClient
246
+ }
247
+
235
248
return & http.Client {
236
249
Transport : & http.Transport {
237
- DisableCompression : ro .DisableCompression ,
250
+ // These are borrowed from the default transporter
251
+ Proxy : http .ProxyFromEnvironment ,
252
+ Dial : (& net.Dialer {
253
+ Timeout : 30 * time .Second ,
254
+ KeepAlive : 30 * time .Second ,
255
+ }).Dial ,
256
+ TLSHandshakeTimeout : 10 * time .Second ,
257
+
258
+ // He comes the user settings
238
259
TLSClientConfig : & tls.Config {InsecureSkipVerify : ro .InsecureSkipVerify },
260
+ DisableCompression : ro .DisableCompression ,
239
261
},
240
262
}
241
-
242
263
}
243
264
244
265
// buildURLParams returns a URL with all of the params
245
266
// Note: This function will override current URL params if they contradict what is provided in the map
246
267
// That is what the "magic" is on the last line
247
- func buildURLParams (userURL string , params map [string ]string ) string {
268
+ func buildURLParams (userURL string , params map [string ]string ) ( string , error ) {
248
269
parsedURL , err := url .Parse (userURL )
249
270
250
271
if err != nil {
251
- return userURL
272
+ return "" , err
252
273
}
253
274
254
275
parsedQuery , err := url .ParseQuery (parsedURL .RawQuery )
@@ -261,7 +282,7 @@ func buildURLParams(userURL string, params map[string]string) string {
261
282
[]string {strings .Replace (parsedURL .String (),
262
283
"?" + parsedURL .RawQuery , "" , - 1 ),
263
284
parsedQuery .Encode ()},
264
- "?" )
285
+ "?" ), nil
265
286
}
266
287
267
288
// addHTTPHeaders adds any additional HTTP headers that need to be added are added here including:
0 commit comments