Skip to content

Commit 5369a62

Browse files
authored
Default to CRT HTTP Client for all EventStreams (#409)
1 parent bfb3a1a commit 5369a62

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

codegen/core/src/main/java/software/amazon/smithy/python/codegen/SmithyPythonDependency.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ public final class SmithyPythonDependency {
3939
Type.DEPENDENCY,
4040
false);
4141

42+
/**
43+
* The awscrt package.
44+
*/
45+
public static final PythonDependency AWS_CRT = new PythonDependency(
46+
"awscrt",
47+
">=0.23.10",
48+
Type.DEPENDENCY,
49+
false);
50+
51+
/**
52+
* The aiohttp package.
53+
*/
54+
public static final PythonDependency AIO_HTTP = new PythonDependency(
55+
"aiohttp",
56+
"~=3",
57+
Type.DEPENDENCY,
58+
false);
59+
4260
/**
4361
* The core smithy-json python package.
4462
*/

codegen/core/src/main/java/software/amazon/smithy/python/codegen/generators/ConfigGenerator.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,17 @@ private static List<ConfigProperty> getHttpProperties(GenerationContext context)
138138
if (usesHttp2(context)) {
139139
clientBuilder
140140
.initialize(writer -> {
141-
writer.addDependency(SmithyPythonDependency.SMITHY_HTTP.withOptionalDependencies("awscrt"));
141+
writer.addDependency(SmithyPythonDependency.SMITHY_HTTP);
142+
writer.addDependency(SmithyPythonDependency.AWS_CRT);
142143
writer.addImport("smithy_http.aio.crt", "AWSCRTHTTPClient");
143144
writer.write("self.http_client = http_client or AWSCRTHTTPClient()");
144145
});
145146

146147
} else {
147148
clientBuilder
148149
.initialize(writer -> {
149-
writer.addDependency(SmithyPythonDependency.SMITHY_HTTP.withOptionalDependencies("aiohttp"));
150+
writer.addDependency(SmithyPythonDependency.SMITHY_HTTP);
151+
writer.addDependency(SmithyPythonDependency.AIO_HTTP);
150152
writer.addImport("smithy_http.aio.aiohttp", "AIOHTTPClient");
151153
writer.write("self.http_client = http_client or AIOHTTPClient()");
152154
});
@@ -171,11 +173,12 @@ private static boolean usesHttp2(GenerationContext context) {
171173
return true;
172174
}
173175

174-
// Bidirectional streaming REQUIRES h2 inherently
176+
// enable CRT/http2 client if the service supports any event streams (single or bi-directional)
177+
// TODO: Long term, only bi-directional evenstreams strictly require h2
175178
var eventIndex = EventStreamIndex.of(context.model());
176179
var topDownIndex = TopDownIndex.of(context.model());
177180
for (OperationShape operation : topDownIndex.getContainedOperations(context.settings().service())) {
178-
if (eventIndex.getInputInfo(operation).isPresent() && eventIndex.getOutputInfo(operation).isPresent()) {
181+
if (eventIndex.getInputInfo(operation).isPresent() || eventIndex.getOutputInfo(operation).isPresent()) {
179182
return true;
180183
}
181184
}

0 commit comments

Comments
 (0)