From 8529421354feb5a2babf61d54263ca4bfedea7ac Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sat, 5 Dec 2026 07:10:36 +0000 Subject: [PATCH] Use `peek` to tell whether a response has a body in the smithy clients ClickHouse gives the SDK a response body that is a stream over the HTTP session: it is only read from, and its `tellp` does not say whether there is anything in it. The legacy clients (`AWSXMLClient`, `AWSProtocolClient.h`) already ask `peek` instead. The clients that are generated on top of `smithy::client::AwsSmithyClientT`, such as the ones of Amazon Bedrock, do not go through that code: `JsonOutcomeSerializer` and `XmlOutcomeSerializer` took every successful response for an empty one, and the error marshallers took every error for one without a body, so its type was guessed from the status code and its message was `No response body.` Ask `peek` there as well: in the two serializers, and in `BuildAWSError` of `JsonErrorMarshaller`, `XmlErrorMarshaller` and `RpcV2ErrorMarshaller`, which only the smithy clients call. The clients that ClickHouse has built so far (S3, KMS, Glue) are legacy ones, so nothing changes for them. Co-Authored-By: Claude Fable 5.2 --- .../smithy/client/serializer/JsonOutcomeSerializer.h | 5 ++++- .../smithy/client/serializer/XmlOutcomeSerializer.h | 5 ++++- .../source/client/AWSErrorMarshaller.cpp | 9 ++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/aws-cpp-sdk-core/include/smithy/client/serializer/JsonOutcomeSerializer.h b/src/aws-cpp-sdk-core/include/smithy/client/serializer/JsonOutcomeSerializer.h index 243a1726d629..1874863f6b42 100644 --- a/src/aws-cpp-sdk-core/include/smithy/client/serializer/JsonOutcomeSerializer.h +++ b/src/aws-cpp-sdk-core/include/smithy/client/serializer/JsonOutcomeSerializer.h @@ -52,8 +52,11 @@ namespace smithy {TracingUtils::SMITHY_SERVICE_DIMENSION, serviceName}}); } + /// ClickHouse: the body is a stream that is only read from, and `tellp` of such a stream + /// does not say whether there is anything in it, so `peek` is asked instead, as in + /// `AWSProtocolClient.h`. if (httpOutcome.GetResult()->GetResponseBody().good() && - httpOutcome.GetResult()->GetResponseBody().tellp() > 0) + httpOutcome.GetResult()->GetResponseBody().peek() != std::char_traits::eof()) { JsonValue jsonValue(httpOutcome.GetResult()->GetResponseBody()); if (!jsonValue.WasParseSuccessful()) { diff --git a/src/aws-cpp-sdk-core/include/smithy/client/serializer/XmlOutcomeSerializer.h b/src/aws-cpp-sdk-core/include/smithy/client/serializer/XmlOutcomeSerializer.h index 61b05f8f9c77..0095d8a74be9 100644 --- a/src/aws-cpp-sdk-core/include/smithy/client/serializer/XmlOutcomeSerializer.h +++ b/src/aws-cpp-sdk-core/include/smithy/client/serializer/XmlOutcomeSerializer.h @@ -53,8 +53,11 @@ namespace smithy {{TracingUtils::SMITHY_METHOD_DIMENSION, requestName}, {TracingUtils::SMITHY_SERVICE_DIMENSION, serviceName}}); } + /// ClickHouse: the body is a stream that is only read from, and `tellp` of such a stream + /// does not say whether there is anything in it, so `peek` is asked instead, as in + /// `AWSProtocolClient.h`. if (httpOutcome.GetResult()->GetResponseBody().good() && - httpOutcome.GetResult()->GetResponseBody().tellp() > 0) + httpOutcome.GetResult()->GetResponseBody().peek() != std::char_traits::eof()) { return TracingUtils::MakeCallWithTiming( [&]() -> XmlOutcome { diff --git a/src/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp b/src/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp index 1768fb9423b1..403a42b6050f 100644 --- a/src/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp +++ b/src/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp @@ -91,7 +91,8 @@ AWSError JsonErrorMarshaller::BuildAWSError(const std::shared_ptrHasClientError()) { bool retryable = httpResponse->GetClientErrorType() == CoreErrors::NETWORK_CONNECTION ? true : false; error = AWSError(httpResponse->GetClientErrorType(), "", httpResponse->GetClientErrorMessage(), retryable); - } else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().tellp() < 1) { + } else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().peek() == std::char_traits::eof()) { + /// ClickHouse: `peek` instead of `tellp`, which a stream that is only read from does not answer. auto responseCode = httpResponse->GetResponseCode(); auto errorCode = GuessBodylessErrorType(responseCode); @@ -175,8 +176,9 @@ AWSError XmlErrorMarshaller::BuildAWSError(const std::shared_ptrGetClientErrorType() == CoreErrors::NETWORK_CONNECTION ? true : false; error = AWSError(httpResponse->GetClientErrorType(), "", httpResponse->GetClientErrorMessage(), retryable); } - else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().tellp() < 1) + else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().peek() == std::char_traits::eof()) { + /// ClickHouse: `peek` instead of `tellp`, which a stream that is only read from does not answer. auto responseCode = httpResponse->GetResponseCode(); auto errorCode = GuessBodylessErrorType(responseCode); @@ -511,7 +513,8 @@ AWSError RpcV2ErrorMarshaller::BuildAWSError(const std::shared_ptrHasClientError()) { bool retryable = httpResponse->GetClientErrorType() == CoreErrors::NETWORK_CONNECTION ? true : false; error = AWSError(httpResponse->GetClientErrorType(), "", httpResponse->GetClientErrorMessage(), retryable); - } else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().tellp() < 1) { + } else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().peek() == std::char_traits::eof()) { + /// ClickHouse: `peek` instead of `tellp`, which a stream that is only read from does not answer. auto responseCode = httpResponse->GetResponseCode(); auto errorCode = GuessBodylessErrorType(responseCode);