Go言語のReverseProxyのFlushIntervalの使用箇所など
$ find ./ -type f -print | xargs grep 'FlushInterval'
code:使用箇所
.//go/api/go1.txt:pkg net/http/httputil, type ReverseProxy struct, FlushInterval time.Duration
.//go/src/net/http/httputil/reverseproxy.go: // FlushInterval specifies the flush interval
.//go/src/net/http/httputil/reverseproxy.go: // The FlushInterval is ignored when ReverseProxy
.//go/src/net/http/httputil/reverseproxy.go: FlushInterval time.Duration
.//go/src/net/http/httputil/reverseproxy.go:// flushInterval returns the p.FlushInterval value, conditionally
.//go/src/net/http/httputil/reverseproxy.go: return p.FlushInterval
.//go/src/net/http/httputil/reverseproxy_test.go:func TestReverseProxyFlushInterval(t *testing.T) {
.//go/src/net/http/httputil/reverseproxy_test.go: proxyHandler.FlushInterval = time.Microsecond
.//go/src/net/http/httputil/reverseproxy_test.go:func TestReverseProxyFlushIntervalHeaders(t *testing.T) {
.//go/src/net/http/httputil/reverseproxy_test.go: proxyHandler.FlushInterval = time.Microsecond
.//go/src/net/http/httputil/reverseproxy_test.go:func TestSelectFlushInterval(t *testing.T) {
.//go/src/net/http/httputil/reverseproxy_test.go: p: &ReverseProxy{FlushInterval: 123},
.//go/src/net/http/httputil/reverseproxy_test.go: p: &ReverseProxy{FlushInterval: 123},
.//go/src/net/http/httputil/reverseproxy_test.go: p: &ReverseProxy{FlushInterval: 0},
reverseproxy.goとそのテストでしか用いられていない。まあこの値を他の場所で読み取って使って影響している可能性はあるが。
主に使用されていると思われるソースコード
code:go
// flushInterval returns the p.FlushInterval value, conditionally
// overriding its value for a specific request/response.
func (p *ReverseProxy) flushInterval(req *http.Request, res *http.Response) time.Duration {
resCT := res.Header.Get("Content-Type")
// For Server-Sent Events responses, flush immediately.
if resCT == "text/event-stream" {
return -1 // negative means immediately
}
// TODO: more specific cases? e.g. res.ContentLength == -1?
return p.FlushInterval
}
func (p *ReverseProxy) copyResponse(dst io.Writer, src io.Reader, flushInterval time.Duration) error {
if flushInterval != 0 {
if wf, ok := dst.(writeFlusher); ok {
mlw := &maxLatencyWriter{
dst: wf,
latency: flushInterval,
}
defer mlw.stop()
// set up initial timer so headers get flushed even if body writes are delayed
mlw.flushPending = true
mlw.t = time.AfterFunc(flushInterval, mlw.delayedFlush)
dst = mlw
}
}
var buf []byte
if p.BufferPool != nil {
buf = p.BufferPool.Get()
defer p.BufferPool.Put(buf)
}
_, err := p.copyBuffer(dst, src, buf)
return err
}
上記のコードで"text/event-stream"だと-1(負の値)になるようになっていて、ストリーミングしたいなら負の値にするのは自然なことのように見える。
// The FlushInterval is ignored when ReverseProxy
// recognizes a response as a streaming response;
// for such responses, writes are flushed to the client
// immediately.