36 lines
888 B
Go
36 lines
888 B
Go
package client
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
const (
|
|
connectionHeaderKey = "Connection"
|
|
connectionUserAgentHeaderKey = "User-Agent"
|
|
connectionCloseHeader = "close"
|
|
connectionKeepAliveHeader = "keep-alive"
|
|
)
|
|
|
|
var (
|
|
connectionCloseHeaderValue = []string{connectionCloseHeader}
|
|
connectionKeepAliveHeaderValue = []string{connectionKeepAliveHeader}
|
|
)
|
|
|
|
type predefinedHeaderTransport struct {
|
|
useragentName []string
|
|
http.Transport
|
|
}
|
|
|
|
func (pht *predefinedHeaderTransport) RoundTrip(req *http.Request) (res *http.Response, err error) {
|
|
var connectionValue []string
|
|
if pht.DisableKeepAlives {
|
|
connectionValue = connectionCloseHeaderValue
|
|
} else {
|
|
connectionValue = connectionKeepAliveHeaderValue
|
|
}
|
|
req.Header[connectionHeaderKey] = connectionValue
|
|
req.Header[connectionUserAgentHeaderKey] = pht.useragentName
|
|
res, err = pht.Transport.RoundTrip(req)
|
|
return
|
|
}
|