|
|
@@ -26,6 +26,9 @@ import (
|
|
|
// backends.
|
|
|
type GetProxyURLs func() []string
|
|
|
|
|
|
+// NewHandler creates a new HTTP handler, listening on the given transport,
|
|
|
+// which will proxy requests to an etcd cluster.
|
|
|
+// The handler will periodically update its view of the cluster.
|
|
|
func NewHandler(t *http.Transport, urlsFunc GetProxyURLs) http.Handler {
|
|
|
return &reverseProxy{
|
|
|
director: newDirector(urlsFunc),
|
|
|
@@ -33,6 +36,12 @@ func NewHandler(t *http.Transport, urlsFunc GetProxyURLs) http.Handler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// NewReadonlyHandler wraps the given HTTP handler to allow only GET requests
|
|
|
+func NewReadonlyHandler(hdlr http.Handler) http.Handler {
|
|
|
+ readonly := readonlyHandlerFunc(hdlr)
|
|
|
+ return http.HandlerFunc(readonly)
|
|
|
+}
|
|
|
+
|
|
|
func readonlyHandlerFunc(next http.Handler) func(http.ResponseWriter, *http.Request) {
|
|
|
return func(w http.ResponseWriter, req *http.Request) {
|
|
|
if req.Method != "GET" {
|
|
|
@@ -43,8 +52,3 @@ func readonlyHandlerFunc(next http.Handler) func(http.ResponseWriter, *http.Requ
|
|
|
next.ServeHTTP(w, req)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-func NewReadonlyHandler(hdlr http.Handler) http.Handler {
|
|
|
- readonly := readonlyHandlerFunc(hdlr)
|
|
|
- return http.HandlerFunc(readonly)
|
|
|
-}
|