add golib/https

This commit is contained in:
AJ ONeal 2021-03-10 16:58:54 -07:00
parent dccf1f108a
commit 5eb3592744
2 changed files with 31 additions and 0 deletions

9
https/README.md Normal file
View File

@ -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)
- [Dont use Gos default HTTP client (in production)](https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779)

22
https/https.go Normal file
View File

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