1
0
Fork 0

Add rqlite version to each HTTP response

master
Philip O Toole 8 years ago
parent 06ae17059b
commit 1b6bdffd33

@ -1,3 +1,6 @@
## 3.3.1 (unreleased)
- [PR #159](https://github.com/rqlite/rqlite/pull/159): All HTTP responses set X-RQLITE-VERSION.
## 3.3.0 (June 1st 2016)
- [PR #151](https://github.com/rqlite/rqlite/pull/151): Support configurable Raft heartbeat timeout.
- [PR #149](https://github.com/rqlite/rqlite/pull/149): Support configurable Raft snapshot thresholds.

@ -193,6 +193,13 @@ func (s *Service) Close() {
// ServeHTTP allows Service to serve HTTP requests.
func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Add version header to every response, if available.
if v, ok := s.BuildInfo["version"].(string); ok {
w.Header().Add("X-RQLITE-VERSION", v)
} else {
w.Header().Add("X-RQLITE-VERSION", "unknown")
}
if s.credentialStore != nil {
username, password, ok := r.BasicAuth()
if !ok || !s.credentialStore.Check(username, password) {

@ -55,6 +55,29 @@ func Test_NewService(t *testing.T) {
}
}
func Test_HasVersionHeader(t *testing.T) {
m := &MockStore{}
s := New("127.0.0.1:0", m, nil)
if err := s.Start(); err != nil {
t.Fatalf("failed to start service")
}
defer s.Close()
s.BuildInfo = map[string]interface{}{
"version": "the version",
}
host := fmt.Sprintf("http://%s", s.Addr().String())
client := &http.Client{}
resp, err := client.Get(host + "/db/xxx")
if err != nil {
t.Fatalf("failed to make request")
}
if resp.Header.Get("X-RQLITE-VERSION") != "the version" {
t.Fatalf("build version not present in HTTP resspone header")
}
}
func Test_404Routes(t *testing.T) {
m := &MockStore{}
s := New("127.0.0.1:0", m, nil)

Loading…
Cancel
Save