From b3ba4fb7b6e53552e0b6bf6749da1b7faca1cb66 Mon Sep 17 00:00:00 2001 From: Jason Del Ponte Date: Thu, 28 Jan 2021 16:23:47 -0800 Subject: [PATCH 1/2] service/lexmodelsv2: Add fix to send expected Content-Type header Fixes the Amazon Lex Model Builder V2 API client to send the expected Content-Type of application/x-amz-json-1.1. --- CHANGELOG_PENDING.md | 2 ++ service/lexmodelsv2/cust_integ_test.go | 20 ++++++++++++++++++++ service/lexmodelsv2/customizations.go | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 service/lexmodelsv2/cust_integ_test.go create mode 100644 service/lexmodelsv2/customizations.go diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 8a1927a39ca..d9270e44081 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -3,3 +3,5 @@ ### SDK Enhancements ### SDK Bugs +* `service/lexmodelsv2`: Add fix to send expected Content-Type header + * Fixes the Amazon Lex Model Builder V2 API client to send the expected Content-Type of application/x-amz-json-1.1. diff --git a/service/lexmodelsv2/cust_integ_test.go b/service/lexmodelsv2/cust_integ_test.go new file mode 100644 index 00000000000..e75418da214 --- /dev/null +++ b/service/lexmodelsv2/cust_integ_test.go @@ -0,0 +1,20 @@ +// +build integration + +package lexmodelsv2 + +import ( + "testing" + + "github.com/aws/aws-sdk-go/awstesting/integration" +) + +func TestInteg_ListBots(t *testing.T) { + sess := integration.SessionWithDefaultRegion("us-west-2") + + client := New(sess) + + _, err := client.ListBots(&ListBotsInput{}) + if err != nil { + t.Fatalf("expect API call, got %v", err) + } +} diff --git a/service/lexmodelsv2/customizations.go b/service/lexmodelsv2/customizations.go new file mode 100644 index 00000000000..1c2745e4436 --- /dev/null +++ b/service/lexmodelsv2/customizations.go @@ -0,0 +1,18 @@ +package lexmodelsv2 + +import ( + "strings" + + "github.com/aws/aws-sdk-go/aws/client" + "github.com/aws/aws-sdk-go/aws/request" +) + +func init() { + initClient = func(c *client.Client) { + c.Handlers.Build.PushBack(func(r *request.Request) { + if strings.EqualFold(r.HTTPRequest.Header.Get("Content-Type"), "application/json") { + r.HTTPRequest.Header.Set("Content-Type", "application/x-amz-json-1.1") + } + }) + } +} From 96c0dd35e7480b8af3c852ddc59a55ffb60fa7d9 Mon Sep 17 00:00:00 2001 From: Jason Del Ponte Date: Thu, 28 Jan 2021 16:42:05 -0800 Subject: [PATCH 2/2] add unit test --- service/lexmodelsv2/customizations_test.go | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 service/lexmodelsv2/customizations_test.go diff --git a/service/lexmodelsv2/customizations_test.go b/service/lexmodelsv2/customizations_test.go new file mode 100644 index 00000000000..f21d01338cd --- /dev/null +++ b/service/lexmodelsv2/customizations_test.go @@ -0,0 +1,37 @@ +package lexmodelsv2 + +import ( + "context" + "net/http" + "net/http/httptest" + "strings" + "testing" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/request" + "github.com/aws/aws-sdk-go/awstesting/unit" +) + +func TestClientContentType(t *testing.T) { + sess := unit.Session.Copy() + + server := httptest.NewServer(http.HandlerFunc( + func(w http.ResponseWriter, r *http.Request) { + contentType := r.Header.Get("Content-Type") + if e, a := contentType, "application/x-amz-json-1.1"; !strings.EqualFold(e, a) { + t.Errorf("expect %v content-type, got %v", e, a) + } + }, + )) + defer server.Close() + + client := New(sess, &aws.Config{Endpoint: &server.URL}) + _, err := client.ListBotsWithContext(context.Background(), + &ListBotsInput{}, + func(r *request.Request) { + }, + ) + if err != nil { + t.Fatalf("expect no error, got %v", err) + } +}