Skip to content

Commit

Permalink
private/protocol: Use correct Content-Type for rest json protocol (a…
Browse files Browse the repository at this point in the history
…ws#2497)

Updates the SDK to use the correct `application/json` content type for
all rest json protocol based AWS services. This fixes the bug where the
jsonrpc protocol's `application/x-amz-json-X.Y` content type would be
used for services like Pinpoint SMS.
  • Loading branch information
jasdel authored Mar 19, 2019
1 parent da2d428 commit 307dd87
Show file tree
Hide file tree
Showing 48 changed files with 131 additions and 66 deletions.
76 changes: 59 additions & 17 deletions models/protocol_tests/input/rest-json.json
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,9 @@
"serialized": {
"body": "{\"Config\": {\"A\": \"one\", \"B\": \"two\"}}",
"uri": "/2014-01-01/jobsByPipeline/foo?Ascending=true&PageToken=bar",
"headers": {}
"headers": {
"Content-Type": "application/json"
}
}
}
]
Expand Down Expand Up @@ -556,7 +558,8 @@
"body": "{\"Config\": {\"A\": \"one\", \"B\": \"two\"}}",
"uri": "/2014-01-01/jobsByPipeline/foo?Ascending=true&PageToken=bar",
"headers": {
"x-amz-checksum": "12345"
"x-amz-checksum": "12345",
"Content-Type": "application/json"
}
}
}
Expand Down Expand Up @@ -672,7 +675,10 @@
},
"serialized": {
"body": "{\"Bar\": \"QmxvYiBwYXJhbQ==\"}",
"uri": "/2014-01-01/foo_name"
"uri": "/2014-01-01/foo_name",
"headers": {
"Content-Type": "application/json"
}
}
}
]
Expand Down Expand Up @@ -789,7 +795,10 @@
"serialized": {
"method": "POST",
"body": "{\"baz\": \"bar\"}",
"uri": "/"
"uri": "/",
"headers": {
"Content-Type": "application/json"
}
}
},
{
Expand Down Expand Up @@ -939,7 +948,9 @@
},
"serialized": {
"uri": "/path" ,
"headers": {},
"headers": {
"Content-Type": "application/json"
},
"body": "{\"RecursiveStruct\": {\"NoRecurse\": \"foo\"}}"
}
},
Expand All @@ -963,7 +974,9 @@
},
"serialized": {
"uri": "/path",
"headers": {},
"headers": {
"Content-Type": "application/json"
},
"body": "{\"RecursiveStruct\": {\"RecursiveStruct\": {\"NoRecurse\": \"foo\"}}}"
}
},
Expand Down Expand Up @@ -991,7 +1004,9 @@
},
"serialized": {
"uri": "/path",
"headers": {},
"headers": {
"Content-Type": "application/json"
},
"body": "{\"RecursiveStruct\": {\"RecursiveStruct\": {\"RecursiveStruct\": {\"RecursiveStruct\": {\"NoRecurse\": \"foo\"}}}}}"
}
},
Expand Down Expand Up @@ -1020,7 +1035,9 @@
},
"serialized": {
"uri": "/path",
"headers": {},
"headers": {
"Content-Type": "application/json"
},
"body": "{\"RecursiveStruct\": {\"RecursiveList\": [{\"NoRecurse\": \"foo\"}, {\"NoRecurse\": \"bar\"}]}}"
}
},
Expand Down Expand Up @@ -1051,7 +1068,9 @@
},
"serialized": {
"uri": "/path",
"headers": {},
"headers": {
"Content-Type": "application/json"
},
"body": "{\"RecursiveStruct\": {\"RecursiveList\": [{\"NoRecurse\": \"foo\"}, {\"RecursiveStruct\": {\"NoRecurse\": \"bar\"}}]}}"
}
},
Expand Down Expand Up @@ -1080,7 +1099,9 @@
},
"serialized": {
"uri": "/path",
"headers": {},
"headers": {
"Content-Type": "application/json"
},
"body": "{\"RecursiveStruct\": {\"RecursiveMap\": {\"foo\": {\"NoRecurse\": \"foo\"}, \"bar\": {\"NoRecurse\": \"bar\"}}}}"
}
}
Expand Down Expand Up @@ -1180,7 +1201,8 @@
"headers": {
"x-amz-timearg": "Sun, 25 Jan 2015 08:00:00 GMT",
"x-amz-timecustom-header": "1422172800",
"x-amz-timeformat-header": "1422172800"
"x-amz-timeformat-header": "1422172800",
"Content-Type": "application/json"
},
"body": "{\"TimeArg\": 1422172800, \"TimeCustom\": \"2015-01-25T08:00:00Z\", \"TimeFormat\": \"Sun, 25 Jan 2015 08:00:00 GMT\"}"
}
Expand Down Expand Up @@ -1224,7 +1246,9 @@
},
"serialized": {
"uri": "/path",
"headers": {},
"headers": {
"Content-Type": "application/json"
},
"body": "{\"timestamp_location\": 1422172800}"
}
}
Expand Down Expand Up @@ -1310,7 +1334,9 @@
},
"serialized": {
"uri": "/path",
"headers": {},
"headers": {
"Content-Type": "application/json"
},
"body": "{\"Token\": \"abc123\"}"
}
},
Expand All @@ -1329,7 +1355,9 @@
},
"serialized": {
"uri": "/path",
"headers": {},
"headers": {
"Content-Type": "application/json"
},
"body": "{\"Token\": \"00000000-0000-4000-8000-000000000000\"}"
}
}
Expand Down Expand Up @@ -1406,7 +1434,10 @@
},
"serialized": {
"uri": "/?Bar=%7B%22Foo%22%3A%22Bar%22%7D",
"headers": {"X-Amz-Foo": "eyJGb28iOiJCYXIifQ=="},
"headers": {
"X-Amz-Foo": "eyJGb28iOiJCYXIifQ==",
"Content-Type": "application/json"
},
"body": "{\"BodyField\":\"{\\\"Foo\\\":\\\"Bar\\\"}\"}"
}
},
Expand All @@ -1427,7 +1458,9 @@
},
"serialized": {
"uri": "/",
"headers": {},
"headers": {
"Content-Type": "application/json"
},
"body": "{\"BodyListField\":[\"{\\\"Foo\\\":\\\"Bar\\\"}\"]}"
}
},
Expand Down Expand Up @@ -1519,7 +1552,10 @@
},
"serialized": {
"uri": "/path?Enum=bar&List=0&List=1&List=",
"headers": {"x-amz-enum": "baz"},
"headers": {
"x-amz-enum": "baz",
"Content-Type": "application/json"
},
"body": "{\"FooEnum\": \"foo\", \"ListEnums\": [\"foo\", \"\", \"bar\"]}"
}
},
Expand Down Expand Up @@ -1592,6 +1628,9 @@
},
"serialized": {
"uri": "/path",
"headers": {
"Content-Type": "application/json"
},
"body": "{\"Name\": \"myname\"}",
"host": "data-service.region.amazonaws.com"
}
Expand All @@ -1615,6 +1654,9 @@
},
"serialized": {
"uri": "/path",
"headers": {
"Content-Type": "application/json"
},
"body": "{\"Name\": \"myname\"}",
"host": "foo-myname.service.region.amazonaws.com"
}
Expand Down
2 changes: 1 addition & 1 deletion private/model/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ func newClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegio
SigningRegion: signingRegion,
Endpoint: endpoint,
APIVersion: "{{ .Metadata.APIVersion }}",
{{ if .Metadata.JSONVersion -}}
{{ if and (.Metadata.JSONVersion) (eq .Metadata.Protocol "json") -}}
JSONVersion: "{{ .Metadata.JSONVersion }}",
{{- end }}
{{ if .Metadata.TargetPrefix -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"metadata":{
"apiVersion":"0000-00-00",
"endpointPrefix":"restjsonservice",
"jsonVersion":"1.1",
"protocol":"rest-json",
"serviceAbbreviation":"RESTJSONService",
"serviceFullName":"REST JSON Service",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"metadata":{
"apiVersion":"0000-00-00",
"endpointPrefix":"restxmlservice",
"jsonVersion":"1.1",
"protocol":"rest-xml",
"serviceAbbreviation":"RESTXMLService",
"serviceFullName":"REST XML Service",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions private/protocol/jsonrpc/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ func Build(req *request.Request) {
target := req.ClientInfo.TargetPrefix + "." + req.Operation.Name
req.HTTPRequest.Header.Add("X-Amz-Target", target)
}
if req.ClientInfo.JSONVersion != "" {

// Only set the content type if one is not already specified and an
// JSONVersion is specified.
if ct, v := req.HTTPRequest.Header.Get("Content-Type"), req.ClientInfo.JSONVersion; len(ct) == 0 && len(v) != 0 {
jsonVersion := req.ClientInfo.JSONVersion
req.HTTPRequest.Header.Add("Content-Type", "application/x-amz-json-"+jsonVersion)
req.HTTPRequest.Header.Set("Content-Type", "application/x-amz-json-"+jsonVersion)
}
}

Expand Down
Loading

0 comments on commit 307dd87

Please sign in to comment.