@@ -72,7 +72,7 @@ public CompletableFuture<AsyncSignedRequest> signAsync(AsyncSignRequest<? extend
7272 Checksummer checksummer = asyncChecksummer (request , checksumStore (request ));
7373 V4Properties v4Properties = v4Properties (request );
7474 V4RequestSigner v4RequestSigner = v4RequestSigner (request , v4Properties );
75- V4PayloadSigner payloadSigner = v4PayloadSigner (request , v4Properties );
75+ V4PayloadSigner payloadSigner = v4PayloadAsyncSigner (request , v4Properties );
7676
7777 return doSignAsync (request , checksummer , v4RequestSigner , payloadSigner );
7878 }
@@ -129,12 +129,10 @@ private static V4RequestSigner v4RequestSigner(
129129 return requestSigner .apply (v4Properties );
130130 }
131131
132+ // TODO: remove this once we consolidate the behavior for plaintext HTTP signing for sync and async
132133 private static Checksummer asyncChecksummer (BaseSignRequest <?, ? extends AwsCredentialsIdentity > request ,
133134 PayloadChecksumStore checksumStore ) {
134- boolean isHttp = !"https" .equals (request .request ().protocol ());
135- boolean isPayloadSigning = isPayloadSigning (request );
136- boolean isChunkEncoding = request .requireProperty (CHUNK_ENCODING_ENABLED , false );
137- boolean shouldTreatAsUnsigned = isHttp && isPayloadSigning && isChunkEncoding ;
135+ boolean shouldTreatAsUnsigned = asyncShouldTreatAsUnsigned (request );
138136
139137 // set the override to false if it should be treated as unsigned, otherwise, null should be passed so that the normal
140138 // check for payload signing is done.
@@ -143,6 +141,15 @@ private static Checksummer asyncChecksummer(BaseSignRequest<?, ? extends AwsCred
143141 return checksummer (request , overridePayloadSigning , checksumStore );
144142 }
145143
144+ // TODO: remove this once we consolidate the behavior for plaintext HTTP signing for sync and async
145+ private static boolean asyncShouldTreatAsUnsigned (BaseSignRequest <?, ? extends AwsCredentialsIdentity > request ) {
146+ boolean isHttp = !"https" .equals (request .request ().protocol ());
147+ boolean isPayloadSigning = isPayloadSigning (request );
148+ boolean isChunkEncoding = request .requireProperty (CHUNK_ENCODING_ENABLED , false );
149+
150+ return isHttp && isPayloadSigning && isChunkEncoding ;
151+ }
152+
146153 private static V4PayloadSigner v4PayloadSigner (
147154 BaseSignRequest <?, ? extends AwsCredentialsIdentity > request , V4Properties properties ) {
148155
@@ -175,6 +182,40 @@ private static V4PayloadSigner v4PayloadSigner(
175182 return V4PayloadSigner .create ();
176183 }
177184
185+ // TODO: remove this once we consolidate the behavior for plaintext HTTP signing for sync and async
186+ private static V4PayloadSigner v4PayloadAsyncSigner (
187+ AsyncSignRequest <? extends AwsCredentialsIdentity > request ,
188+ V4Properties properties ) {
189+
190+ boolean isPayloadSigning = !asyncShouldTreatAsUnsigned (request );
191+ boolean isEventStreaming = isEventStreaming (request .request ());
192+ boolean isChunkEncoding = request .requireProperty (CHUNK_ENCODING_ENABLED , false );
193+ boolean isTrailing = request .request ().firstMatchingHeader (X_AMZ_TRAILER ).isPresent ();
194+ boolean isFlexible = request .hasProperty (CHECKSUM_ALGORITHM ) && !hasChecksumHeader (request );
195+
196+ if (isEventStreaming ) {
197+ if (isPayloadSigning ) {
198+ return getEventStreamV4PayloadSigner (
199+ properties .getCredentials (),
200+ properties .getCredentialScope (),
201+ properties .getSigningClock ()
202+ );
203+ }
204+ throw new UnsupportedOperationException ("Unsigned payload is not supported with event-streaming." );
205+ }
206+
207+ if (useChunkEncoding (isPayloadSigning , isChunkEncoding , isTrailing || isFlexible )) {
208+ return AwsChunkedV4PayloadSigner .builder ()
209+ .credentialScope (properties .getCredentialScope ())
210+ .chunkSize (DEFAULT_CHUNK_SIZE_IN_BYTES )
211+ .checksumStore (checksumStore (request ))
212+ .checksumAlgorithm (request .property (CHECKSUM_ALGORITHM ))
213+ .build ();
214+ }
215+
216+ return V4PayloadSigner .create ();
217+ }
218+
178219 private static SignedRequest doSign (SignRequest <? extends AwsCredentialsIdentity > request ,
179220 Checksummer checksummer ,
180221 V4RequestSigner requestSigner ,
0 commit comments