-
Notifications
You must be signed in to change notification settings - Fork 179
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
Add user-agent to requests #176
Conversation
Hi, @kfdm! Thanks for your contribution, but could you tell me why is this needed? |
This would affect how it shows up in server logs
Better to explicitly set the user agent to help with debugging, instead of leaving the generic default. I still want to see if I can get the proper version in there to make this as |
@kfdm We could probably pass the version on plugin initialization and then set it in http/jwt backend. On the idea itself, I don't feel comfortable hardcoding the user agent. Instead, I'd add options that allow it to be set however the user wants, e.g.:
|
By the way, these are defined at
|
Thank you for the feedback! 🙇 Though I have not implemented yet, instead of two fields how about a single value?
I am still trying to think of a clean way to get the version number. I feel like there is probably a cleaner way to handle the version than this, so I'm still thinking through it GoInt data[3] = {LIBMOSQUITTO_MAJOR, LIBMOSQUITTO_MINOR, LIBMOSQUITTO_REVISION};
GoSlice version = {data, 3, 3};
AuthPluginInit(keysSlice, valuesSlice, opts_count, version); |
@kfdm I don't agree with defaulting to Likewise, since we're already adding options, I don't see a reason to impose the appended version: let the user decide if they want to attach it or not.
Mm... maybe a simple |
@kfdm any updates on this? I like the general idea, but would like my last comment to be addressed. Let me know if you're available to do so, or if I should take care of it. Cheers! |
Thank you for checking back. I allowed myself to get distracted by some other things. I feel like I have to respectfully disagree with you a bit on the default bit. I will yield to you on the specific version number, if you are worried about that from a security perspective. As an operator, I feel like the least surprising behavior is for an application to provide a user agent. It can be rather frustrating on the infrastructure side, to try to track down a random script that uses that languages' default user-agent. The current behavior is defaulting to sending an incorrect agent (from the perspective of an operator) |
@kfdm Yeah, you might be right. I don't really feel very strongly about it, maybe the fact that it'd be a change that would probably go unnoticed but could in fact surprise users (hey, why is there this user agent all of a sudden?) had me leaning towards not changing it by default. But let's just default to |
I've rebased to make sure there are no issues. There's not a specific changelog file in the repository itself, so I'm not sure if there's a specific place to call out the update to the default user-agent |
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.
Thanks for rebasing! Will you add Mosquitto's version? If so, please also add tests for both backends with and without having versions passed along.
backends/http.go
Outdated
@@ -79,6 +80,11 @@ func NewHTTP(authOpts map[string]string, logLevel log.Level) (HTTP, error) { | |||
missingOpts += " http_aclcheck_uri" | |||
} | |||
|
|||
http.UserAgent = "mosquitto" |
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.
Can we make the default a constant? Also, feel free not to export it, i.e. userAgent
instead of UserAgent
. I just haven't gotten to refactor http
like I did with jwt
backend.
backends/jwt_remote.go
Outdated
@@ -80,6 +81,11 @@ func NewRemoteJWTChecker(authOpts map[string]string, options tokenOptions) (jwtC | |||
missingOpts += " jwt_aclcheck_uri" | |||
} | |||
|
|||
checker.userAgent = "mosquitto" |
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.
Same here.
I think adding to the README and documenting Mosquitto's version once you add it is enough, then I can mention the change ion the next release as I usually do. |
I think I'll leave off the version number for now. Can always try to attempt it again, but my earlier attempts to try to get the version number from the mosquitto side were not as clean as I had hoped. Both http.go and jwt_remote.go are in the same backend package, so I put Would you prefer me to rebase everything into a single commit, or will you do that as part of the final merge? |
Cool, Thanks again! |
That looks great! I'm not picky about getting credit for it. My work was quite simple. I'm also fine with you closing this PR and merging yours if that makes it easiest for you :) |
It was your idea, @kfdm, I just added the version, so credit where credit is due. |
Add more room for extended versions.
Ok, I think I succeeded in rebasing correctly. It's now in two commits. Git kept trying to assign the edit to me XD so I think I fixed that with Let me know if it still looks ok. |
Cool then, let's merge it. Thanks, Paul! |
This avoids the default go
Go-http-client/1.1
User-Agent in requests.Ideally I would have this as
mosquitto/<version>
though I'm unsure how to read the Mosquitto version yet. Any pointers?