summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/yohcop/openid-go/getter.go
blob: a21019f0ff667869643b489765d0a79441adc974 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package openid

import (
	"net/http"
	"net/url"
)

// Interface that simplifies testing.
type httpGetter interface {
	Get(uri string, headers map[string]string) (resp *http.Response, err error)
	Post(uri string, form url.Values) (resp *http.Response, err error)
}

type defaultGetter struct {
	client *http.Client
}

func (dg *defaultGetter) Get(uri string, headers map[string]string) (resp *http.Response, err error) {
	request, err := http.NewRequest("GET", uri, nil)
	if err != nil {
		return
	}
	for h, v := range headers {
		request.Header.Add(h, v)
	}
	return dg.client.Do(request)
}

func (dg *defaultGetter) Post(uri string, form url.Values) (resp *http.Response, err error) {
	return dg.client.PostForm(uri, form)
}