go-http-default-request-header-transporter .github/workflows/check.yml codecov Go Reference

A utility http.Transport to inject the given default request header.

Synopsis

import (
	"http"
	"time"

	"github.com/moznion/go-http-default-request-header-transporter"
)

func main() {
	defaultHeader := http.Header{}
	defaultHeader.Set("user-agent", "custom-UA/0.0.1")
	defaultHeader.Add("x-test", "foo")
	defaultHeader.Add("x-test", "bar")

	hc := &http.Client{}
	hc.Timeout = 3 * time.Second
	hc.Transport = transporter.NewDefaultRequestHeaderTransporter(hc.Transport, defaultHeader)
	resp, err := hc.Get(httpURL) // <= this request header has the values of `defaultHeader`
}

Please also refer to the examples_test.go.

Documentations

Go Reference

Author

moznion ([email protected])

GitHub

View Github