Browse Source

add golib/https

master
AJ ONeal 3 years ago
parent
commit
5eb3592744
  1. 9
      https/README.md
  2. 22
      https/https.go

9
https/README.md

@ -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)

22
https/https.go

@ -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…
Cancel
Save