diff options
author | Brad Fitzpatrick <bradfitz@golang.org> | 2018-11-05 16:26:45 +0000 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2018-11-14 21:07:02 +0000 |
commit | bfd9b94069e74b0c6516a045cbb83bf1024a1269 (patch) | |
tree | ba017b7c5b061b122f2f4d889bd88c761bfa220d /src/net/http/transport_test.go | |
parent | 0c7762cd184649552309c82671bf81f89d215ff7 (diff) | |
download | go-bfd9b94069e74b0c6516a045cbb83bf1024a1269.tar.gz go-bfd9b94069e74b0c6516a045cbb83bf1024a1269.zip |
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 <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Diffstat (limited to 'src/net/http/transport_test.go')
-rw-r--r-- | src/net/http/transport_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index 3f9750392c..22ca3f9550 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -4952,3 +4952,56 @@ func TestTransportCONNECTBidi(t *testing.T) { } } } + +func TestTransportRequestReplayable(t *testing.T) { + someBody := ioutil.NopCloser(strings.NewReader("")) + tests := []struct { + name string + req *Request + want bool + }{ + { + name: "GET", + req: &Request{Method: "GET"}, + want: true, + }, + { + name: "GET_http.NoBody", + req: &Request{Method: "GET", Body: NoBody}, + want: true, + }, + { + name: "GET_body", + req: &Request{Method: "GET", Body: someBody}, + want: false, + }, + { + name: "POST", + req: &Request{Method: "POST"}, + want: false, + }, + { + name: "POST_idempotency-key", + req: &Request{Method: "POST", Header: Header{"Idempotency-Key": {"x"}}}, + want: true, + }, + { + name: "POST_x-idempotency-key", + req: &Request{Method: "POST", Header: Header{"X-Idempotency-Key": {"x"}}}, + want: true, + }, + { + name: "POST_body", + req: &Request{Method: "POST", Header: Header{"Idempotency-Key": {"x"}}, Body: someBody}, + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.req.ExportIsReplayable() + if got != tt.want { + t.Errorf("replyable = %v; want %v", got, tt.want) + } + }) + } +} |