Documentation ¶
Overview ¶
Package hsts implements a RoundTripper that supports HTTP Strict Transport Security.
It comes preloaded with sites from Chromium (https://www.chromium.org/hsts), updated with go generate.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport implements a RoundTripper adding HSTS to an existing RoundTripper.
func New ¶
func New(transport http.RoundTripper) *Transport
New wraps around a RoundTripper transport to add HTTP Strict Transport Security (HSTS). It starts preloaded with Chromium's list (https://www.chromium.org/hsts). Just like an http.Client if transport is nil, http.DefaultTransport is used.
Example ¶
client := http.DefaultClient // Wrap around the client's transport to add HSTS support. client.Transport = New(client.Transport) // Assuming example.com has set up HSTS, we learn it at the first HTTPS request. resp, err := client.Get("https://example.com") if err != nil { log.Fatal(err) } defer resp.Body.Close() // So that any following request made in insecure HTTP would go in HTTPS. resp, err = client.Get("http://example.com") // will become HTTPS if err != nil { log.Fatal(err) } defer resp.Body.Close()
Output:
Click to show internal directories.
Click to hide internal directories.