File: getter.go

package info (click to toggle)
golang-github-yohcop-openid-go 0.0~git20170901.0.cfc72ed-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 184 kB
  • sloc: makefile: 3
file content (31 lines) | stat: -rw-r--r-- 725 bytes parent folder | download
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)
}