in core/protocols/aws-json-protocol/src/main/java/software/amazon/awssdk/protocols/json/internal/marshall/JsonProtocolMarshaller.java [258:303]
private SdkHttpFullRequest finishMarshalling() {
// Content may already be set if the payload is binary data.
if (request.contentStreamProvider() == null) {
// End the implicit request object if needed.
if (needTopLevelJsonObject()) {
jsonGenerator.writeEndObject();
}
byte[] content = jsonGenerator.getBytes();
if (content != null) {
request.contentStreamProvider(() -> new ByteArrayInputStream(content));
if (content.length > 0) {
request.putHeader(CONTENT_LENGTH, Integer.toString(content.length));
}
}
}
// We skip setting the default content type if the request is streaming as
// content-type is determined based on the body of the stream
// TODO: !request.headers().containsKey(CONTENT_TYPE) does not work because request is created from line 77
// and not from the original request
if (!request.firstMatchingHeader(CONTENT_TYPE).isPresent() && !hasEvent) {
if (hasEventStreamingInput) {
AwsJsonProtocol protocol = protocolMetadata.protocol();
if (protocol == AwsJsonProtocol.AWS_JSON || protocol == AwsJsonProtocol.SMITHY_RPC_V2_CBOR) {
// For RPC formats, this content type will later be pushed down into the `initial-event` in the body
request.putHeader(CONTENT_TYPE, contentType);
} else if (protocol == AwsJsonProtocol.REST_JSON) {
request.putHeader(CONTENT_TYPE, MIMETYPE_EVENT_STREAM);
} else {
throw new IllegalArgumentException("Unknown AwsJsonProtocol: " + protocol);
}
request.removeHeader(CONTENT_LENGTH);
request.putHeader(TRANSFER_ENCODING, CHUNKED);
} else if (contentType != null && !hasStreamingInput && request.firstMatchingHeader(CONTENT_LENGTH).isPresent()) {
request.putHeader(CONTENT_TYPE, contentType);
}
}
if (hasAwsQueryCompatible) {
request.putHeader("x-amzn-query-mode", "true");
}
return request.build();
}