Skip to content

Commit 9b9ef29

Browse files
committed
Fix headers for Event streaming & fix AddPathSegment bug
1 parent 6fbaa48 commit 9b9ef29

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

tools/code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/generators/cpp/CborCppClientGenerator.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ protected SdkFileEntry generateModelHeaderFile(ServiceModel serviceModel, Map.En
9090

9191
@Override
9292
protected SdkFileEntry generateModelSourceFile(ServiceModel serviceModel, Map.Entry<String, Shape> shapeEntry, final Map<String, CppShapeInformation> shapeInformationCache) {
93-
Map<String, String> cborSpecificHeaders = new HashMap<>();
94-
cborSpecificHeaders.put("Accept", "application/cbor");
95-
cborSpecificHeaders.put("smithy-protocol", "rpc-v2-cbor");
96-
serviceModel.getMetadata().setAdditionalHeaders(cborSpecificHeaders);
97-
9893
Shape shape = shapeEntry.getValue();
9994
if (shape.isResult() && shape.hasEventStreamMembers())
10095
return null;
@@ -126,11 +121,20 @@ protected SdkFileEntry generateModelSourceFile(ServiceModel serviceModel, Map.En
126121
if (shape.hasEventStreamMembers()) {
127122
HashMap<String, String> headersMap = new HashMap<>(10);
128123
headersMap.put("Aws::Http::CONTENT_TYPE_HEADER", "Aws::AMZN_EVENTSTREAM_CONTENT_TYPE");
124+
headersMap.put("Aws::Http::ACCEPT_HEADER", "Aws::AMZN_EVENTSTREAM_CONTENT_TYPE");
125+
headersMap.put("\"smithy-protocol\"", "\"rpc-v2-cbor\"");
129126
context.put("requestSpecificHeaders", headersMap);
130127
}
131128
template = velocityEngine.getTemplate("/com/amazonaws/util/awsclientgenerator/velocity/cpp/StreamRequestSource.vm", StandardCharsets.UTF_8.name());
132129
}
133130
else if (shape.isRequest()) {
131+
Map<String, String> cborSpecificHeaders = new HashMap<>();
132+
cborSpecificHeaders.put("Aws::Http::ACCEPT_HEADER", "Aws::CBOR_CONTENT_TYPE");
133+
cborSpecificHeaders.put("\"smithy-protocol\"", "\"rpc-v2-cbor\"");
134+
if(shape.hasMembers()){
135+
cborSpecificHeaders.put("Aws::Http::CONTENT_TYPE_HEADER", "Aws::CBOR_CONTENT_TYPE");
136+
}
137+
context.put("requestSpecificHeaders", cborSpecificHeaders);
134138
template = velocityEngine.getTemplate("/com/amazonaws/util/awsclientgenerator/velocity/cpp/cbor/CborRequestSource.vm", StandardCharsets.UTF_8.name());
135139
}
136140
else if (shape.isResult() && shape.hasStreamMembers()) {

tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/cbor/CborRequestSource.vm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
Aws::Http::HeaderValueCollection ${typeInfo.className}::GetRequestSpecificHeaders() const
6464
{
6565
Aws::Http::HeaderValueCollection headers;
66-
#if($shape.hasMembers())
67-
headers.emplace(Aws::Http::HeaderValuePair(Aws::Http::CONTENT_TYPE_HEADER, Aws::CBOR_CONTENT_TYPE ));
66+
#foreach($headerEntry in $requestSpecificHeaders.entrySet())
67+
headers.emplace(${headerEntry.key}, ${headerEntry.value});
6868
#end
6969
#parse("com/amazonaws/util/awsclientgenerator/velocity/cpp/ModelClassHeaderMembersSource.vm")
7070
return headers;

tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/common/UriRequestQueryParams.vm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ${indent} return;
3737
${indent} }
3838
#end
3939
#if($metadata.findFirstSupportedProtocol() == "smithy-rpc-v2-cbor")
40-
${indent} endpointResolutionOutcome.GetResult().AddPathSegment("/service/${serviceModel.metadata.targetPrefix}/operation/${operation.name}");
40+
${indent} endpointResolutionOutcome.GetResult().AddPathSegments("/service/${serviceModel.metadata.targetPrefix}/operation/${operation.name}");
4141
#end
4242
#if($operation.http.requestUri.contains("?"))
4343
${indent} Aws::StringStream ss;

0 commit comments

Comments
 (0)