grafana/devenv/docker/blocks/slow_proxy/main.go
Carl Bergquist b426ff5292
devenv: add slow reverse proxy (#16943)
this can be useful when testing timeouts etc
in the dataproxy

ref #16923
2019-05-08 10:09:48 +02:00

32 lines
580 B
Go

package main
import (
"fmt"
"log"
"net/http"
"net/http/httputil"
"net/url"
"os"
"time"
)
func main() {
origin := os.Getenv("ORIGIN_SERVER")
if origin == "" {
origin = "http://localhost:9090/"
}
sleep := time.Minute
originURL, _ := url.Parse(origin)
proxy := httputil.NewSingleHostReverseProxy(originURL)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Printf("sleeping for %s then proxying request: %s", sleep.String(), r.RequestURI)
<-time.After(sleep)
proxy.ServeHTTP(w, r)
})
log.Fatal(http.ListenAndServe(":3011", nil))
}