proxy: send proxy version in user-agent header
This commit is contained in:
@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"crypto/sha512"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@ -106,8 +107,7 @@ func getTLSTransport() http.RoundTripper {
|
||||
// NewAPIController initialise new API Controller instance from URL and API token
|
||||
func NewAPIController(pbURL url.URL, token string) *APIController {
|
||||
transport := httptransport.New(pbURL.Host, client.DefaultBasePath, []string{pbURL.Scheme})
|
||||
|
||||
transport.Transport = getTLSTransport()
|
||||
transport.Transport = SetUserAgent(getTLSTransport(), fmt.Sprintf("passbook-proxy@%s", pkg.VERSION))
|
||||
|
||||
// create the transport
|
||||
auth := httptransport.BasicAuth("", token)
|
||||
|
20
proxy/pkg/server/api_uag.go
Normal file
20
proxy/pkg/server/api_uag.go
Normal file
@ -0,0 +1,20 @@
|
||||
package server
|
||||
|
||||
import "net/http"
|
||||
|
||||
func SetUserAgent(inner http.RoundTripper, userAgent string) http.RoundTripper {
|
||||
return &addUGA{
|
||||
inner: inner,
|
||||
Agent: userAgent,
|
||||
}
|
||||
}
|
||||
|
||||
type addUGA struct {
|
||||
inner http.RoundTripper
|
||||
Agent string
|
||||
}
|
||||
|
||||
func (ug *addUGA) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||
r.Header.Set("User-Agent", ug.Agent)
|
||||
return ug.inner.RoundTrip(r)
|
||||
}
|
@ -24,6 +24,7 @@ func (ac *APIController) initWS(pbURL url.URL, outpostUUID strfmt.UUID) {
|
||||
|
||||
header := http.Header{
|
||||
"Authorization": []string{authHeader},
|
||||
"User-Agent": []string{fmt.Sprintf("passbook-proxy@%s", pkg.VERSION)},
|
||||
}
|
||||
|
||||
value, set := os.LookupEnv("PASSBOOK_INSECURE")
|
||||
|
Reference in New Issue
Block a user