in codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/integration/HttpProtocolUtils.java [51:107]
public static List<RuntimeClientPlugin> getCloseResponseClientPlugins(
BiPredicate<Model, ServiceShape> servicePredicate
) {
return ListUtils.of(
// Add deserialization middleware to close the response in case of errors.
RuntimeClientPlugin.builder()
.servicePredicate(servicePredicate)
.operationPredicate((model, service, operation) -> {
var eventStreamIndex = EventStreamIndex.of(model);
return eventStreamIndex.getInputInfo(operation).isEmpty()
&& eventStreamIndex.getOutputInfo(operation).isEmpty();
})
.registerMiddleware(MiddlewareRegistrar.builder()
.resolvedFunction(SymbolUtils.createValueSymbolBuilder(
"AddErrorCloseResponseBodyMiddleware",
SmithyGoDependency.SMITHY_HTTP_TRANSPORT)
.build())
.build()
)
.build(),
// Add deserialization middleware to close the response for non-output-streaming operations.
RuntimeClientPlugin.builder()
.servicePredicate(servicePredicate)
.operationPredicate((model, service, operation) -> {
// Don't auto close response body when response is streaming.
HttpBindingIndex httpBindingIndex = HttpBindingIndex.of(model);
Optional<HttpBinding> payloadBinding = httpBindingIndex.getResponseBindings(operation,
HttpBinding.Location.PAYLOAD).stream().findFirst();
var eventStreamIndex = EventStreamIndex.of(model);
if (eventStreamIndex.getInputInfo(operation).isPresent()
|| eventStreamIndex.getOutputInfo(operation).isPresent()) {
return false;
}
if (payloadBinding.isPresent()) {
MemberShape memberShape = payloadBinding.get().getMember();
Shape payloadShape = model.expectShape(memberShape.getTarget());
return !payloadShape.hasTrait(StreamingTrait.class);
}
return true;
})
.registerMiddleware(MiddlewareRegistrar.builder()
.resolvedFunction(SymbolUtils.createValueSymbolBuilder(
"AddCloseResponseBodyMiddleware",
SmithyGoDependency.SMITHY_HTTP_TRANSPORT)
.build())
.build()
)
.build()
);
}