这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Conversation

@inkel
Copy link
Contributor

@inkel inkel commented Jun 23, 2015

Use a custom http.Client for sending HTTP notifications, adding a proper User-Agent header with the Bosun/{{version}} format. The version only includes the version number and release tag, not the most recent commit hash nor build time.

Review on Reviewable

@inkel
Copy link
Contributor Author

inkel commented Jun 23, 2015

This change only covers adding the User-Agent header. The HTTP notification code could use a refactor to removing some duplication in the code.

The version package could also be refactored to include either a method returning the value for the User-Agent instead of having to build the userAgent variable in the init function.

@captncraig
Copy link
Contributor

We already set http.DefaultClient to a custom client here:

client := &http.Client{

Any changes should be made there. Adding a "ShortVersion()" function to the version package would be ok by me as well.

@inkel
Copy link
Contributor Author

inkel commented Jun 24, 2015

@captncraig ah, great, I'll use http.DefaultClient then. Sadly, custom headers cannot be set in the default client but only in Request.Header, unless I'm missing something. I'll double check.

I'll work on the ShortVersion function too.

@captncraig
Copy link
Contributor

I would think we should set up out main client to set the user-agent on every request. That can be done with a custom RoundTripper. Something like this: https://play.golang.org/p/_E6fRYPvrN

@inkel inkel force-pushed the http-notification-user-agent branch from 605ff23 to 02b1d03 Compare June 24, 2015 23:16
@inkel
Copy link
Contributor Author

inkel commented Jun 24, 2015

@captncraig I've applied your suggestions. I think the initialization of the client could probably be done in a nicer way than this. I'd like to know your thoughts.

@captncraig
Copy link
Contributor

LGTM. How do you feel about this implementation @mjibson ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not set this if it already exists.

@madelynnblue
Copy link
Contributor

Implementation looks good after my one comment. What problem does this solve, or why is it needed?

@inkel
Copy link
Contributor Author

inkel commented Jul 8, 2015

What problem does this solve, or why is it needed?

It isn't really a problem what is solving, maybe a best practice. At work we're working on a custom notifications aggregator, which several other services sending HTTP notifications. We record all the information received and use the User-Agent header to identify which service was the one sending the notification. I'm aware HTTP headers are easily spoofed, but this will mostly internal, so it's not a concern. And in our case, using the User-Agent for identification is easier than checking the remote IP, for instance.

I'll see to fix that line you pointed me, sorry for the delay. Thanks!

@captncraig
Copy link
Contributor

Closing. Will merge commit in #1265

@captncraig captncraig closed this Aug 19, 2015
@inkel
Copy link
Contributor Author

inkel commented Aug 19, 2015

Thanks!

@inkel inkel deleted the http-notification-user-agent branch August 19, 2015 20:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants