Skip to content

Commit

Permalink
added flushinterval for opts
Browse files Browse the repository at this point in the history
  • Loading branch information
javier.molina authored and javier.molina committed May 8, 2019
1 parent 6e15729 commit 18bf779
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions proxy/http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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":
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sort"
"strconv"
"strings"
"time"

"github.com/fabiolb/fabio/metrics"
"github.com/gobwas/glob"
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 3 additions & 0 deletions route/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package route
import (
"net/url"
"strings"
"time"

"github.com/fabiolb/fabio/metrics"
)
Expand Down Expand Up @@ -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{}
}
Expand Down

0 comments on commit 18bf779

Please sign in to comment.