mirror of https://github.com/therootcompany/golib
AJ ONeal
3 years ago
2 changed files with 31 additions and 0 deletions
@ -0,0 +1,9 @@ |
|||||
|
# https (as in secure) |
||||
|
|
||||
|
This wrappers and helpers to supplement Go's built-in `net/http` with reasonable and safe defaults. |
||||
|
|
||||
|
See |
||||
|
|
||||
|
- [The complete guide to Go net/http timeouts](https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/) |
||||
|
- [Standard net/http config will break your production environment](https://medium.com/@simonfrey/go-as-in-golang-standard-net-http-config-will-break-your-production-environment-1360871cb72b) |
||||
|
- [Don’t use Go’s default HTTP client (in production)](https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779) |
@ -0,0 +1,22 @@ |
|||||
|
package https |
||||
|
|
||||
|
import ( |
||||
|
"net" |
||||
|
"net/http" |
||||
|
"time" |
||||
|
) |
||||
|
|
||||
|
// NewHTTPClient creates a new http client with reasonable and safe defaults
|
||||
|
func NewHTTPClient() *http.Client { |
||||
|
transport := &http.Transport{ |
||||
|
Dial: (&net.Dialer{ |
||||
|
Timeout: 10 * time.Second, |
||||
|
}).Dial, |
||||
|
TLSHandshakeTimeout: 5 * time.Second, |
||||
|
} |
||||
|
client := &http.Client{ |
||||
|
Timeout: time.Second * 5, |
||||
|
Transport: transport, |
||||
|
} |
||||
|
return client |
||||
|
} |
Loading…
Reference in new issue