@@ -72,7 +72,7 @@ public CompletableFuture<AsyncSignedRequest> signAsync(AsyncSignRequest<? extend
72
72
Checksummer checksummer = asyncChecksummer (request , checksumStore (request ));
73
73
V4Properties v4Properties = v4Properties (request );
74
74
V4RequestSigner v4RequestSigner = v4RequestSigner (request , v4Properties );
75
- V4PayloadSigner payloadSigner = v4PayloadSigner (request , v4Properties );
75
+ V4PayloadSigner payloadSigner = v4PayloadAsyncSigner (request , v4Properties );
76
76
77
77
return doSignAsync (request , checksummer , v4RequestSigner , payloadSigner );
78
78
}
@@ -129,12 +129,10 @@ private static V4RequestSigner v4RequestSigner(
129
129
return requestSigner .apply (v4Properties );
130
130
}
131
131
132
+ // TODO: remove this once we consolidate the behavior for plaintext HTTP signing for sync and async
132
133
private static Checksummer asyncChecksummer (BaseSignRequest <?, ? extends AwsCredentialsIdentity > request ,
133
134
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 );
138
136
139
137
// set the override to false if it should be treated as unsigned, otherwise, null should be passed so that the normal
140
138
// check for payload signing is done.
@@ -143,6 +141,15 @@ private static Checksummer asyncChecksummer(BaseSignRequest<?, ? extends AwsCred
143
141
return checksummer (request , overridePayloadSigning , checksumStore );
144
142
}
145
143
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
+
146
153
private static V4PayloadSigner v4PayloadSigner (
147
154
BaseSignRequest <?, ? extends AwsCredentialsIdentity > request , V4Properties properties ) {
148
155
@@ -175,6 +182,40 @@ private static V4PayloadSigner v4PayloadSigner(
175
182
return V4PayloadSigner .create ();
176
183
}
177
184
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
+
178
219
private static SignedRequest doSign (SignRequest <? extends AwsCredentialsIdentity > request ,
179
220
Checksummer checksummer ,
180
221
V4RequestSigner requestSigner ,
0 commit comments