You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
725 B

  1. package openid
  2. import (
  3. "net/http"
  4. "net/url"
  5. )
  6. // Interface that simplifies testing.
  7. type httpGetter interface {
  8. Get(uri string, headers map[string]string) (resp *http.Response, err error)
  9. Post(uri string, form url.Values) (resp *http.Response, err error)
  10. }
  11. type defaultGetter struct {
  12. client *http.Client
  13. }
  14. func (dg *defaultGetter) Get(uri string, headers map[string]string) (resp *http.Response, err error) {
  15. request, err := http.NewRequest("GET", uri, nil)
  16. if err != nil {
  17. return
  18. }
  19. for h, v := range headers {
  20. request.Header.Add(h, v)
  21. }
  22. return dg.client.Do(request)
  23. }
  24. func (dg *defaultGetter) Post(uri string, form url.Values) (resp *http.Response, err error) {
  25. return dg.client.PostForm(uri, form)
  26. }