From 5bbb854cee2df329e031e50181ccc022c9d93a85 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Sat, 4 Jun 2016 23:26:12 -0700 Subject: [PATCH] net/http/httputil: preallocate trailerKeys slice To prevent slice growths with append operations. Change-Id: Icdb745b23cc44dfaf3e16746b94c06997f814e15 Reviewed-on: https://go-review.googlesource.com/23784 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/net/http/httputil/reverseproxy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net/http/httputil/reverseproxy.go b/src/net/http/httputil/reverseproxy.go index f8b60b6d33..76f23bcf9a 100644 --- a/src/net/http/httputil/reverseproxy.go +++ b/src/net/http/httputil/reverseproxy.go @@ -221,7 +221,7 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { // The "Trailer" header isn't included in the Transport's response, // at least for *http.Transport. Build it up from Trailer. if len(res.Trailer) > 0 { - var trailerKeys []string + trailerKeys := make([]string, 0, len(res.Trailer)) for k := range res.Trailer { trailerKeys = append(trailerKeys, k) }