From bfd9b94069e74b0c6516a045cbb83bf1024a1269 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 5 Nov 2018 16:26:45 +0000 Subject: net/http: make Transport respect {X-,}Idempotency-Key header Fixes #19943 Change-Id: I5e0fefe44791d7b3556095d726c2a753ec551ef2 Reviewed-on: https://go-review.googlesource.com/c/147457 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Dmitri Shuralyov --- src/net/http/request.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/net/http/request.go') diff --git a/src/net/http/request.go b/src/net/http/request.go index 0bcdeae0df..5b7e6564ae 100644 --- a/src/net/http/request.go +++ b/src/net/http/request.go @@ -579,7 +579,7 @@ func (r *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, waitF // Use the defaultUserAgent unless the Header contains one, which // may be blank to not send the header. userAgent := defaultUserAgent - if _, ok := r.Header["User-Agent"]; ok { + if r.Header.has("User-Agent") { userAgent = r.Header.Get("User-Agent") } if userAgent != "" { @@ -1345,6 +1345,12 @@ func (r *Request) isReplayable() bool { case "GET", "HEAD", "OPTIONS", "TRACE": return true } + // The Idempotency-Key, while non-standard, is widely used to + // mean a POST or other request is idempotent. See + // https://golang.org/issue/19943#issuecomment-421092421 + if r.Header.has("Idempotency-Key") || r.Header.has("X-Idempotency-Key") { + return true + } } return false } -- cgit v1.2.1