From 998ce1c4262aab0153b5e89f84ef2ddd57507ec7 Mon Sep 17 00:00:00 2001 From: Jes Cok Date: Thu, 12 Sep 2024 17:15:58 +0000 Subject: [PATCH] net/http: make use of maps.Copy Change-Id: If8e02760fe1fb095ecebc306fd98662a51a1f66f GitHub-Last-Rev: 7b8099f1fed04271c121cdde1c3abd8822955368 GitHub-Pull-Request: golang/go#69426 Reviewed-on: https://go-review.googlesource.com/c/go/+/612736 Reviewed-by: Tim King LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- src/net/http/server.go | 4 +--- src/net/http/transfer.go | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/net/http/server.go b/src/net/http/server.go index 371c6601453..0b56edf2310 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -3683,9 +3683,7 @@ func (h *timeoutHandler) ServeHTTP(w ResponseWriter, r *Request) { tw.mu.Lock() defer tw.mu.Unlock() dst := w.Header() - for k, vv := range tw.h { - dst[k] = vv - } + maps.Copy(dst, tw.h) if !tw.wroteHeader { tw.code = StatusOK } diff --git a/src/net/http/transfer.go b/src/net/http/transfer.go index f7eef6475e6..675551287fa 100644 --- a/src/net/http/transfer.go +++ b/src/net/http/transfer.go @@ -11,6 +11,7 @@ import ( "fmt" "internal/godebug" "io" + "maps" "net/http/httptrace" "net/http/internal" "net/http/internal/ascii" @@ -954,9 +955,7 @@ func mergeSetHeader(dst *Header, src Header) { *dst = src return } - for k, vv := range src { - (*dst)[k] = vv - } + maps.Copy(*dst, src) } // unreadDataSizeLocked returns the number of bytes of unread input.