example_test.go 784 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package hpkp_test
  2. import (
  3. "log"
  4. "net/http"
  5. "github.com/tam7t/hpkp"
  6. )
  7. func Example() {
  8. s := hpkp.NewMemStorage()
  9. s.Add("github.com", &hpkp.Header{
  10. Permanent: true,
  11. Sha256Pins: []string{
  12. "WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18=",
  13. "RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=",
  14. "k2v657xBsOVe1PQRwOsHsw3bsGT2VzIqz5K+59sNQws=",
  15. "K87oWBWM9UZfyddvDfoxL+8lpNyoUB2ptGtn0fv6G2Q=",
  16. "IQBnNBEiFuhj+8x6X8XLgh01V9Ic5/V3IRQLNFFc7v4=",
  17. "iie1VXtL7HzAMF+/PVPR9xzT80kQxdZeJ+zduCB3uj0=",
  18. "LvRiGEjRqfzurezaWuj8Wie2gyHMrW5Q06LspMnox7A=",
  19. },
  20. })
  21. client := &http.Client{}
  22. client.Transport = &http.Transport{
  23. DialTLS: hpkp.PinOnlyDialer(s),
  24. }
  25. resp, err := client.Get("https://github.com")
  26. if err != nil {
  27. log.Fatal(err)
  28. }
  29. log.Println(resp.StatusCode)
  30. }