-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use single http client for cli #441
Conversation
7a2d222
to
062467b
Compare
003d5dd
to
72825a1
Compare
client/client.go
Outdated
} | ||
defer resp.Body.Close() | ||
|
||
result, err := io.ReadAll(resp.Body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should be part of send
instead, since it's duplicated in 3 other function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review from fresh look and moved also request initiazliation inside and remove checking by specific http status code, so now client.go looks even smaller.
74e1ba0
to
d178282
Compare
Initialize single http client to request api server. Specify User-Agent and Content-Type. Parse error response in single place.
bf379c2
to
48d5c8a
Compare
Introduce single Client httpClient for all cli requests.
It allows to add request headers in single place.
For example adds
User-Agent
HTTP header for all requests as"toxiproxy-cli/<version> <os>/<runtime>"
.Parse response on success or errors.
Set content type as json always.