Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Can we set a User-Agent header? #911
We would like to be able to set an arbitrary user-agent header either at client generation time or at compile time. Is it possible to do this?
The Swagger specification is irrelevant in this case because we are using the same specification to generate many clients.
You can use a custom transport which allows you to set the user agent.
And you can configure it with this constructor method
You can also configure that runtime with a stdlib http.Client
You can extend intercept a http request with the http.RoundTripper interface. https://godoc.org/net/http#RoundTripper
which you can set here: https://github.com/go-openapi/runtime/blob/master/client/runtime.go#L116
var myRoundTripper http.RoundTripper = createRoundTripper() transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes) transport.Transport = myRoundTripper todoListClient := New(transport, nil)