Skip to content

Commit

Permalink
Update CBOR to always have an accept header
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp committed Oct 13, 2024
1 parent 0b2a323 commit b7f5652
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
26 changes: 26 additions & 0 deletions codegen/projections/rpcv2_cbor/lib/rpcv2_cbor/builders.rb

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

Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public BuilderGeneratorBase(GenerationContext context) {
*
* @param operation the operation to generate for.
* @param inputShape the operation's input.
* @param isEventStream true when the operations input has an event stream.
* @param isEventStream true when the operations input has an event stream.
*/
protected abstract void renderOperationBuildMethod(OperationShape operation, Shape inputShape,
boolean isEventStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ protected void renderOperationBuildMethod(OperationShape operation, Shape inputS
.write("http_req.http_method = 'POST'")
.write("http_req.append_path('/service/$L/operation/$L')",
context.service().getId().getName(), operation.getId().getName())
.call(() -> {
renderContentTypeHeader(operation, isEventStream);
})
.call(() -> renderHeaders(operation, isEventStream))
.call(() -> {
if (isEventStream) {
renderEventStreamInitialRequestMessage(inputShape);
Expand Down Expand Up @@ -120,15 +118,26 @@ private void renderEventStreamInitialRequestMessage(Shape inputShape) {
}
}

private void renderContentTypeHeader(OperationShape operation, boolean isEventStream) {
if (isEventStream) {
writer.write("http_req.headers['Content-Type'] = 'application/vnd.amazon.eventstream'");
if (Streaming.isEventStreaming(model, model.expectShape(operation.getOutputShape()))) {
writer.write("http_req.headers['Accept'] = 'application/vnd.amazon.eventstream'");
private void renderHeaders(OperationShape operation, boolean isEventStream) {
writer.write("http_req.headers['Smithy-Protocol'] = 'rpc-v2-cbor'");

if (!model.expectShape(operation.getInputShape()).hasTrait(UnitTypeTrait.class)) {
String contentTypeHeader;
if (isEventStream) {
contentTypeHeader = "application/vnd.amazon.eventstream";
} else {
contentTypeHeader = "application/cbor";
}
writer.write("http_req.headers['Content-Type'] = '$L'", contentTypeHeader);
}

String acceptHeader;
if (Streaming.isEventStreaming(model, model.expectShape(operation.getOutputShape()))) {
acceptHeader = "application/vnd.amazon.eventstream";
} else {
writer.write("http_req.headers['Smithy-Protocol'] = 'rpc-v2-cbor'");
acceptHeader = "application/cbor";
}
writer.write("http_req.headers['Accept'] = '$L'", acceptHeader);
}

@Override
Expand Down

0 comments on commit b7f5652

Please sign in to comment.