diff --git a/proxy/pool.go b/proxy/pool.go deleted file mode 100644 index fe2cf4a5..00000000 --- a/proxy/pool.go +++ /dev/null @@ -1,29 +0,0 @@ -package proxy - -import ( - "sync" -) - -type bufferPool struct { - // A bufferPool must not be copied after first use. - // https://golang.org/pkg/sync/#Pool - buffers sync.Pool -} - -func newBufferPool(bufferSize int) *bufferPool { - return &bufferPool{ - buffers: sync.Pool{ - New: func() interface{} { - return make([]byte, bufferSize) - }, - }, - } -} - -func (p *bufferPool) Get() []byte { - return p.buffers.Get().([]byte) -} - -func (p *bufferPool) Put(buf []byte) { - p.buffers.Put(buf) -} diff --git a/proxy/proxy.go b/proxy/proxy.go index 5ec8743b..3ab3c370 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -12,6 +12,7 @@ import ( "github.com/rs/zerolog" "github.com/cloudflare/cloudflared/carrier" + "github.com/cloudflare/cloudflared/cfio" "github.com/cloudflare/cloudflared/connection" "github.com/cloudflare/cloudflared/ingress" tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs" @@ -32,7 +33,6 @@ type Proxy struct { warpRouting *ingress.WarpRoutingService tags []tunnelpogs.Tag log *zerolog.Logger - bufferPool *bufferPool } // NewOriginProxy returns a new instance of the Proxy struct. @@ -46,7 +46,6 @@ func NewOriginProxy( ingressRules: ingressRules, tags: tags, log: log, - bufferPool: newBufferPool(512 * 1024), } if warpRoutingEnabled { proxy.warpRouting = ingress.NewWarpRoutingService() @@ -218,11 +217,7 @@ func (p *Proxy) proxyHTTPRequest( p.log.Debug().Msg("Detected Server-Side Events from Origin") p.writeEventStream(w, resp.Body) } else { - // Use CopyBuffer, because Copy only allocates a 32KiB buffer, and cross-stream - // compression generates dictionary on first write - buf := p.bufferPool.Get() - defer p.bufferPool.Put(buf) - _, _ = io.CopyBuffer(w, resp.Body, buf) + _, _ = cfio.Copy(w, resp.Body) } p.logOriginResponse(resp, fields)