From 18bf779472dc6f46808519e52246915b669ceb56 Mon Sep 17 00:00:00 2001 From: "javier.molina" Date: Wed, 8 May 2019 12:06:04 +0200 Subject: [PATCH] added flushinterval for opts --- proxy/http_proxy.go | 8 ++++++-- route/route.go | 9 +++++++++ route/target.go | 3 +++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/proxy/http_proxy.go b/proxy/http_proxy.go index 2991cad56..380842774 100644 --- a/proxy/http_proxy.go +++ b/proxy/http_proxy.go @@ -114,6 +114,7 @@ func (p *HTTPProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { Host: t.URL.Host, Path: r.URL.Path, } + if t.URL.RawQuery == "" || r.URL.RawQuery == "" { targetURL.RawQuery = t.URL.RawQuery + r.URL.RawQuery } else { @@ -150,7 +151,6 @@ func (p *HTTPProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { if t.TLSSkipVerify { tr = p.InsecureTransport } - var h http.Handler switch { case upgrade == "websocket" || upgrade == "Websocket": @@ -169,7 +169,7 @@ func (p *HTTPProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { h = newHTTPProxy(targetURL, tr, p.Config.FlushInterval) default: - h = newHTTPProxy(targetURL, tr, time.Duration(0)) + h = newHTTPProxy(targetURL, tr, t.FlushInterval) } if p.Config.GZIPContentTypes != nil { @@ -247,6 +247,10 @@ func (rw *responseWriter) WriteHeader(statusCode int) { rw.code = statusCode } +func (rw *responseWriter) Flush() { + rw.w.(http.Flusher).Flush() +} + var errNoHijacker = errors.New("not a hijacker") func (rw *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { diff --git a/route/route.go b/route/route.go index 0f9e35dc9..a567d31cb 100644 --- a/route/route.go +++ b/route/route.go @@ -8,6 +8,7 @@ import ( "sort" "strconv" "strings" + "time" "github.com/fabiolb/fabio/metrics" "github.com/gobwas/glob" @@ -85,6 +86,14 @@ func (r *Route) addTarget(service string, targetURL *url.URL, fixedWeight float6 } } + if fi := opts["flush"]; fi != "" { + if duration, err := time.ParseDuration(fi); err != nil { + log.Printf("[ERROR] Flush Interval should be a duration. Got: %s", fi) + } else { + t.FlushInterval = duration + } + } + if err = t.ProcessAccessRules(); err != nil { log.Printf("[ERROR] failed to process access rules: %s", err.Error()) diff --git a/route/target.go b/route/target.go index 08a1e36dc..35dca8944 100644 --- a/route/target.go +++ b/route/target.go @@ -3,6 +3,7 @@ package route import ( "net/url" "strings" + "time" "github.com/fabiolb/fabio/metrics" ) @@ -55,6 +56,8 @@ type Target struct { // TimerName is the name of the timer in the metrics registry TimerName string + FlushInterval time.Duration + // accessRules is map of access information for the target. accessRules map[string][]interface{} }