Skip to content

Commit a12199d

Browse files
Use seekable bodies for requests
This updates requests to use seekable bodies wherever possible so that they can be retried.
1 parent 07e203d commit a12199d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

codegen/smithy-python-codegen/src/main/java/software/amazon/smithy/python/codegen/integration/RestJsonProtocolGenerator.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ protected void serializeDocumentBody(
138138
) {
139139
writer.addDependency(SmithyPythonDependency.SMITHY_JSON);
140140
writer.addImport("smithy_json", "JSONCodec");
141-
writer.addImport("smithy_core.aio.types", "AsyncBytesReader");
141+
writer.addImport("smithy_core.aio.types", "SeekableAsyncBytesReader");
142142

143143
writer.pushState();
144144

145145
if (documentBindings.isEmpty()) {
146146
var body = shouldWriteDefaultBody(context, operation) ? "b'{}'" : "b''";
147147
writer.write("""
148148
content_length = 0
149-
body = AsyncBytesReader($L)
149+
body = SeekableAsyncBytesReader($L)
150150
""", body);
151151
} else {
152152
writer.addImport("smithy_core.types", "TimestampFormat");
@@ -159,7 +159,7 @@ protected void serializeDocumentBody(
159159
content = b'{}'
160160
${/writeDefaultBody}
161161
content_length = len(content)
162-
body = AsyncBytesReader(content)
162+
body = SeekableAsyncBytesReader(content)
163163
""");
164164
}
165165

@@ -223,13 +223,13 @@ protected void serializePayloadBody(
223223
return;
224224
}
225225

226-
writer.addImport("smithy_core.aio.types", "AsyncBytesReader");
226+
writer.addImport("smithy_core.aio.types", "SeekableAsyncBytesReader");
227227
writer.write("content_length: int = 0");
228228

229229
CodegenUtils.accessStructureMember(context, writer, "input", payloadBinding.getMember(), () -> {
230230
if (target.isBlobShape()) {
231231
writer.write("content_length = len($L)", dataSource);
232-
writer.write("body = AsyncBytesReader($L)", dataSource);
232+
writer.write("body = SeekableAsyncBytesReader($L)", dataSource);
233233
return;
234234
}
235235

@@ -244,13 +244,13 @@ protected void serializePayloadBody(
244244
""", dataSource);
245245
}
246246
writer.write("content_length = len(content)");
247-
writer.write("body = AsyncBytesReader(content)");
247+
writer.write("body = SeekableAsyncBytesReader(content)");
248248
});
249249
if (target.isStructureShape()) {
250250
writer.write("""
251251
else:
252252
content_length = 2
253-
body = AsyncBytesReader(b'{}')
253+
body = SeekableAsyncBytesReader(b'{}')
254254
""");
255255
}
256256
}

0 commit comments

Comments
 (0)