|
|
@@ -41,13 +41,13 @@ func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error {
|
|
|
stream := (req.FormValue("stream") == "true")
|
|
|
|
|
|
if req.FormValue("wait") == "true" {
|
|
|
- return handleWatch(key, recursive, stream, waitIndex, w, s)
|
|
|
+ return handleWatch(key, recursive, stream, waitIndex, w, req, s)
|
|
|
}
|
|
|
|
|
|
- return handleGet(key, recursive, sort, w, s)
|
|
|
+ return handleGet(key, recursive, sort, w, req, s)
|
|
|
}
|
|
|
|
|
|
-func handleWatch(key string, recursive, stream bool, waitIndex string, w http.ResponseWriter, s Server) error {
|
|
|
+func handleWatch(key string, recursive, stream bool, waitIndex string, w http.ResponseWriter, req *http.Request, s Server) error {
|
|
|
// Create a command to watch from a given index (default 0).
|
|
|
var sinceIndex uint64 = 0
|
|
|
var err error
|
|
|
@@ -84,6 +84,9 @@ func handleWatch(key string, recursive, stream bool, waitIndex string, w http.Re
|
|
|
// send to the client in time. Then we simply end streaming.
|
|
|
return nil
|
|
|
}
|
|
|
+ if req.Method == "HEAD" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
|
|
|
b, _ := json.Marshal(event)
|
|
|
_, err := w.Write(b)
|
|
|
@@ -99,18 +102,25 @@ func handleWatch(key string, recursive, stream bool, waitIndex string, w http.Re
|
|
|
case <-closeChan:
|
|
|
watcher.Remove()
|
|
|
case event := <-watcher.EventChan:
|
|
|
+ if req.Method == "HEAD" {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
b, _ := json.Marshal(event)
|
|
|
w.Write(b)
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func handleGet(key string, recursive, sort bool, w http.ResponseWriter, s Server) error {
|
|
|
+func handleGet(key string, recursive, sort bool, w http.ResponseWriter, req *http.Request, s Server) error {
|
|
|
event, err := s.Store().Get(key, recursive, sort)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
+ if req.Method == "HEAD" {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
writeHeaders(w, s)
|
|
|
b, _ := json.Marshal(event)
|
|
|
w.Write(b)
|