@@ -193,7 +193,7 @@ type BackendStats struct {
193
193
194
194
// ErrorHandler called by httputil.ReverseProxy for errors.
195
195
// Avoid canceled context error since it means the client disconnected.
196
- func (b * Backend ) ErrorHandler (w http.ResponseWriter , r * http.Request , err error ) {
196
+ func (b * Backend ) ErrorHandler (_ http.ResponseWriter , _ * http.Request , err error ) {
197
197
if err != nil && ! errors .Is (err , context .Canceled ) {
198
198
if globalLoggingEnabled {
199
199
logMsg (logMessage {Endpoint : b .endpoint , Status : "down" , Error : err })
@@ -418,7 +418,7 @@ func (s *site) ServeHTTP(w http.ResponseWriter, r *http.Request) {
418
418
if backend != nil && backend .Online () {
419
419
cacheHandlerFn := func (w http.ResponseWriter , r * http.Request ) {
420
420
if backend .cacheClient != nil {
421
- cacheHandler (w , r , backend )(w , r )
421
+ cacheHandler (backend )(w , r )
422
422
} else {
423
423
backend .proxy .ServeHTTP (w , r )
424
424
}
@@ -589,6 +589,34 @@ func checkMain(ctx *cli.Context) {
589
589
}
590
590
}
591
591
592
+ func modifyResponse () func (* http.Response ) error {
593
+ return func (resp * http.Response ) error {
594
+ resp .Header .Set ("X-Proxy" , "true" )
595
+ return nil
596
+ }
597
+ }
598
+
599
+ type bufPool struct {
600
+ pool sync.Pool
601
+ }
602
+
603
+ func (b * bufPool ) Put (buf []byte ) {
604
+ b .pool .Put (buf )
605
+ }
606
+
607
+ func (b * bufPool ) Get () []byte {
608
+ return b .pool .Get ().([]byte )
609
+ }
610
+
611
+ func newBufPool (sz int ) httputil.BufferPool {
612
+ return & bufPool {pool : sync.Pool {
613
+ New : func () interface {} {
614
+ buf := make ([]byte , sz )
615
+ return buf
616
+ },
617
+ }}
618
+ }
619
+
592
620
func configureSite (ctx * cli.Context , siteNum int , siteStrs []string , healthCheckPath string , healthCheckPort int , healthCheckDuration time.Duration ) * site {
593
621
var endpoints []string
594
622
@@ -649,9 +677,10 @@ func configureSite(ctx *cli.Context, siteNum int, siteStrs []string, healthCheck
649
677
r .URL .Scheme = target .Scheme
650
678
r .URL .Host = target .Host
651
679
},
652
- Transport : transport ,
680
+ Transport : transport ,
681
+ BufferPool : newBufPool (128 << 10 ),
682
+ ModifyResponse : modifyResponse (),
653
683
}
654
-
655
684
stats := BackendStats {MinLatency : 24 * time .Hour , MaxLatency : 0 }
656
685
healthCheckURL , err := getHealthCheckURL (endpoint , healthCheckPath , healthCheckPort )
657
686
if err != nil {
0 commit comments