-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
pass along version to httpd/handler #2928
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ type route struct { | |
type Handler struct { | ||
mux *pat.PatternServeMux | ||
requireAuthentication bool | ||
version string | ||
Version string | ||
|
||
MetaStore interface { | ||
Database(name string) (*meta.DatabaseInfo, error) | ||
|
@@ -75,13 +75,12 @@ type Handler struct { | |
} | ||
|
||
// NewHandler returns a new instance of handler with routes. | ||
func NewHandler(requireAuthentication, loggingEnabled bool, version string) *Handler { | ||
func NewHandler(requireAuthentication, loggingEnabled bool) *Handler { | ||
h := &Handler{ | ||
mux: pat.New(), | ||
requireAuthentication: requireAuthentication, | ||
Logger: log.New(os.Stderr, "[http] ", log.LstdFlags), | ||
loggingEnabled: loggingEnabled, | ||
version: version, | ||
} | ||
|
||
h.SetRoutes([]route{ | ||
|
@@ -134,7 +133,7 @@ func (h *Handler) SetRoutes(routes []route) { | |
if r.gzipped { | ||
handler = gzipFilter(handler) | ||
} | ||
handler = versionHeader(handler, h.version) | ||
handler = versionHeader(handler, h) | ||
handler = cors(handler) | ||
handler = requestID(handler) | ||
if h.loggingEnabled && r.log { | ||
|
@@ -662,9 +661,9 @@ func gzipFilter(inner http.Handler) http.Handler { | |
|
||
// versionHeader taks a HTTP handler and returns a HTTP handler | ||
// and adds the X-INFLUXBD-VERSION header to outgoing responses. | ||
func versionHeader(inner http.Handler, version string) http.Handler { | ||
func versionHeader(inner http.Handler, h *Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Add("X-InfluxDB-Version", version) | ||
w.Header().Add("X-InfluxDB-Version", h.Version) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to the above comment, same thing. Restricting scope for arguments is important. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, I see what you did now that I looked at the file as a whole. I guess I'm fine making the signatures consistent. Ignore my previous comments :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually the reason for it is that at the time |
||
inner.ServeHTTP(w, r) | ||
}) | ||
} | ||
|
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 typically prefer to only send what is needed to the receiving method, which in this case is just the version string. It makes the receiving function easy to understand what is actually needed.