Skip to content

Commit

Permalink
Set User-Agent based on version of tsuru-client
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Mar 18, 2024
1 parent 11af4ef commit 888c138
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions tsuru/http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (v *TerminalRoundTripper) RoundTrip(req *http.Request) (*http.Response, err
}
verbosity := getVerbosity()
req.Header.Add(verbosityHeader, strconv.Itoa(verbosity))
req.Header.Set("User-Agent", fmt.Sprintf("tsuru-client/%s", v.CurrentVersion))
req.Close = true

if verbosity >= TerminalClientOnlyRequest {
Expand Down
8 changes: 6 additions & 2 deletions tsuru/http/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ func (s *S) TestVerboseRoundTripperDumpRequest(c *check.C) {
}()
out := new(bytes.Buffer)
r := TerminalRoundTripper{
Stdout: out,
Stdout: out,
CurrentVersion: "1.0.0",
RoundTripper: &cmdtest.Transport{
Message: "Success!",
Status: http.StatusOK,
Expand All @@ -31,6 +32,7 @@ func (s *S) TestVerboseRoundTripperDumpRequest(c *check.C) {
c.Assert(out.String(), check.DeepEquals, "*************************** <Request uri=\"/users\"> **********************************\n"+
"GET /users HTTP/1.1\r\n"+
"Host: localhost\r\n"+
"User-Agent: tsuru-client/1.0.0\r\n"+
"X-Tsuru-Verbosity: 1\r\n"+
"\r\n"+
"*************************** </Request uri=\"/users\"> **********************************\n")
Expand All @@ -44,7 +46,8 @@ func (s *S) TestVerboseRoundTripperDumpRequestResponse2(c *check.C) {

out := new(bytes.Buffer)
r := TerminalRoundTripper{
Stdout: out,
Stdout: out,
CurrentVersion: "1.2.0",
RoundTripper: &cmdtest.Transport{
Message: "Success!",
Status: http.StatusOK,
Expand All @@ -57,6 +60,7 @@ func (s *S) TestVerboseRoundTripperDumpRequestResponse2(c *check.C) {
c.Assert(out.String(), check.DeepEquals, "*************************** <Request uri=\"/users\"> **********************************\n"+
"GET /users HTTP/1.1\r\n"+
"Host: localhost\r\n"+
"User-Agent: tsuru-client/1.2.0\r\n"+
"X-Tsuru-Verbosity: 2\r\n"+
"\r\n"+
"*************************** </Request uri=\"/users\"> **********************************\n"+
Expand Down

0 comments on commit 888c138

Please sign in to comment.