summaryrefslogtreecommitdiff
path: root/libgo/go/net/http/httputil/reverseproxy.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/net/http/httputil/reverseproxy.go')
-rw-r--r--libgo/go/net/http/httputil/reverseproxy.go26
1 files changed, 24 insertions, 2 deletions
diff --git a/libgo/go/net/http/httputil/reverseproxy.go b/libgo/go/net/http/httputil/reverseproxy.go
index c8e113221c4..4dba352a4fa 100644
--- a/libgo/go/net/http/httputil/reverseproxy.go
+++ b/libgo/go/net/http/httputil/reverseproxy.go
@@ -46,6 +46,18 @@ type ReverseProxy struct {
// If nil, logging goes to os.Stderr via the log package's
// standard logger.
ErrorLog *log.Logger
+
+ // BufferPool optionally specifies a buffer pool to
+ // get byte slices for use by io.CopyBuffer when
+ // copying HTTP response bodies.
+ BufferPool BufferPool
+}
+
+// A BufferPool is an interface for getting and returning temporary
+// byte slices for use by io.CopyBuffer.
+type BufferPool interface {
+ Get() []byte
+ Put([]byte)
}
func singleJoiningSlash(a, b string) string {
@@ -60,10 +72,13 @@ func singleJoiningSlash(a, b string) string {
return a + b
}
-// NewSingleHostReverseProxy returns a new ReverseProxy that rewrites
+// NewSingleHostReverseProxy returns a new ReverseProxy that routes
// URLs to the scheme, host, and base path provided in target. If the
// target's path is "/base" and the incoming request was for "/dir",
// the target request will be for /base/dir.
+// NewSingleHostReverseProxy does not rewrite the Host header.
+// To rewrite Host headers, use ReverseProxy directly with a custom
+// Director policy.
func NewSingleHostReverseProxy(target *url.URL) *ReverseProxy {
targetQuery := target.RawQuery
director := func(req *http.Request) {
@@ -242,7 +257,14 @@ func (p *ReverseProxy) copyResponse(dst io.Writer, src io.Reader) {
}
}
- io.Copy(dst, src)
+ var buf []byte
+ if p.BufferPool != nil {
+ buf = p.BufferPool.Get()
+ }
+ io.CopyBuffer(dst, src, buf)
+ if p.BufferPool != nil {
+ p.BufferPool.Put(buf)
+ }
}
func (p *ReverseProxy) logf(format string, args ...interface{}) {