24
24
import static com .adobe .testing .s3mock .S3Exception .NOT_MODIFIED ;
25
25
import static com .adobe .testing .s3mock .S3Exception .NO_SUCH_KEY ;
26
26
import static com .adobe .testing .s3mock .S3Exception .PRECONDITION_FAILED ;
27
+ import static com .adobe .testing .s3mock .util .AwsHttpHeaders .X_AMZ_CHECKSUM ;
27
28
import static com .adobe .testing .s3mock .util .AwsHttpHeaders .X_AMZ_DECODED_CONTENT_LENGTH ;
29
+ import static com .adobe .testing .s3mock .util .AwsHttpHeaders .X_AMZ_TRAILER ;
28
30
import static com .adobe .testing .s3mock .util .HeaderUtil .checksumAlgorithmFromSdk ;
29
31
import static com .adobe .testing .s3mock .util .HeaderUtil .isChunked ;
30
32
import static com .adobe .testing .s3mock .util .HeaderUtil .isChunkedAndV4Signed ;
37
39
import com .adobe .testing .s3mock .dto .Delete ;
38
40
import com .adobe .testing .s3mock .dto .DeleteResult ;
39
41
import com .adobe .testing .s3mock .dto .DeletedS3Object ;
42
+ import com .adobe .testing .s3mock .dto .Error ;
40
43
import com .adobe .testing .s3mock .dto .LegalHold ;
41
44
import com .adobe .testing .s3mock .dto .Owner ;
42
45
import com .adobe .testing .s3mock .dto .Retention ;
45
48
import com .adobe .testing .s3mock .store .BucketStore ;
46
49
import com .adobe .testing .s3mock .store .ObjectStore ;
47
50
import com .adobe .testing .s3mock .store .S3ObjectMetadata ;
48
- import com .adobe .testing .s3mock .util .AbstractAwsInputStream ;
49
- import com .adobe .testing .s3mock .util .AwsChunkedDecodingChecksumInputStream ;
50
- import com .adobe .testing .s3mock .util .AwsUnsignedChunkedDecodingChecksumInputStream ;
51
+ import com .adobe .testing .s3mock .util .AwsChunkedInputStream ;
51
52
import com .adobe .testing .s3mock .util .DigestUtil ;
52
53
import java .io .IOException ;
53
54
import java .io .InputStream ;
@@ -161,7 +162,7 @@ public DeleteResult deleteObjects(String bucketName, Delete delete) {
161
162
response .addDeletedObject (DeletedS3Object .from (object ));
162
163
} catch (IllegalStateException e ) {
163
164
response .addError (
164
- new com . adobe . testing . s3mock . dto . Error ("InternalError" ,
165
+ new Error ("InternalError" ,
165
166
object .key (),
166
167
"We encountered an internal error. Please try again." ,
167
168
object .versionId ()));
@@ -266,13 +267,13 @@ public void verifyRetention(Retention retention) {
266
267
267
268
public Pair <Path , String > toTempFile (InputStream inputStream , HttpHeaders httpHeaders ) {
268
269
try {
269
- var tempFile = Files .createTempFile ("tempObject " , "" );
270
+ var tempFile = Files .createTempFile ("ObjectService " , "toTempFile " );
270
271
try (OutputStream os = Files .newOutputStream (tempFile )) {
271
272
InputStream wrappedStream = wrapStream (inputStream , httpHeaders );
272
273
wrappedStream .transferTo (os );
273
274
ChecksumAlgorithm algorithmFromSdk = checksumAlgorithmFromSdk (httpHeaders );
274
275
if (algorithmFromSdk != null
275
- && wrappedStream instanceof AbstractAwsInputStream awsInputStream ) {
276
+ && wrappedStream instanceof AwsChunkedInputStream awsInputStream ) {
276
277
return Pair .of (tempFile , awsInputStream .getChecksum ());
277
278
}
278
279
return Pair .of (tempFile , null );
@@ -291,11 +292,11 @@ public void verifyChecksum(Path path, String checksum, ChecksumAlgorithm checksu
291
292
292
293
InputStream wrapStream (InputStream dataStream , HttpHeaders headers ) {
293
294
var lengthHeader = headers .getFirst (X_AMZ_DECODED_CONTENT_LENGTH );
295
+ var trailHeader = headers .getOrEmpty (X_AMZ_TRAILER );
296
+ var hasChecksum = trailHeader .stream ().anyMatch (h -> h .contains (X_AMZ_CHECKSUM ));
294
297
var length = lengthHeader == null ? -1 : Long .parseLong (lengthHeader );
295
- if (isChunkedAndV4Signed (headers )) {
296
- return new AwsChunkedDecodingChecksumInputStream (dataStream , length );
297
- } else if (isChunked (headers )) {
298
- return new AwsUnsignedChunkedDecodingChecksumInputStream (dataStream , length );
298
+ if (isChunkedAndV4Signed (headers ) || isChunked (headers )) {
299
+ return new AwsChunkedInputStream (dataStream , length , hasChecksum );
299
300
} else {
300
301
return dataStream ;
301
302
}
0 commit comments