mirror of
https://github.com/caddyserver/caddy.git
synced 2025-02-03 23:09:57 -05:00
middleware: ResponseRecorder now is an http.Flusher (fixes #677)
Flush every 250ms. This should keep latency somewhat low but there is still buffering; maybe in the future we can make this configurable.
This commit is contained in:
parent
c21ff8343c
commit
3faad41b43
2 changed files with 9 additions and 1 deletions
|
@ -111,7 +111,7 @@ func NewSingleHostReverseProxy(target *url.URL, without string) *ReverseProxy {
|
||||||
req.URL.Path = strings.TrimPrefix(req.URL.Path, without)
|
req.URL.Path = strings.TrimPrefix(req.URL.Path, without)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rp := &ReverseProxy{Director: director}
|
rp := &ReverseProxy{Director: director, FlushInterval: 250 * time.Millisecond} // flushing good for streaming & server-sent events
|
||||||
if target.Scheme == "unix" {
|
if target.Scheme == "unix" {
|
||||||
rp.Transport = &http.Transport{
|
rp.Transport = &http.Transport{
|
||||||
Dial: socketDial(target.String()),
|
Dial: socketDial(target.String()),
|
||||||
|
|
|
@ -77,3 +77,11 @@ func (r *ResponseRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||||
}
|
}
|
||||||
return nil, nil, errors.New("not a Hijacker")
|
return nil, nil, errors.New("not a Hijacker")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flush implements http.Flusher. It simply wraps the underlying
|
||||||
|
// ResponseWriter's Flush method if there is one, or does nothing.
|
||||||
|
func (r *ResponseRecorder) Flush() {
|
||||||
|
if f, ok := r.ResponseWriter.(http.Flusher); ok {
|
||||||
|
f.Flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue