File: http_transport.go

package info (click to toggle)
golang-github-hashicorp-terraform-svchost 0.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 260 kB
  • sloc: makefile: 5; sh: 4
file content (30 lines) | stat: -rw-r--r-- 605 bytes parent folder | download | duplicates (3)
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
package disco

import (
	"net/http"

	"github.com/hashicorp/go-cleanhttp"
)

const DefaultUserAgent = "terraform-svchost/1.0"

func defaultHttpTransport() http.RoundTripper {
	t := cleanhttp.DefaultPooledTransport()
	return &userAgentRoundTripper{
		innerRt:   t,
		userAgent: DefaultUserAgent,
	}
}

type userAgentRoundTripper struct {
	innerRt   http.RoundTripper
	userAgent string
}

func (rt *userAgentRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
	if _, ok := req.Header["User-Agent"]; !ok {
		req.Header.Set("User-Agent", rt.userAgent)
	}

	return rt.innerRt.RoundTrip(req)
}