|
20 | 20 | import java.io.ByteArrayOutputStream;
|
21 | 21 | import java.io.IOException;
|
22 | 22 | import java.io.UncheckedIOException;
|
| 23 | +import java.util.Arrays; |
| 24 | +import java.util.List; |
23 | 25 | import software.amazon.awssdk.annotations.SdkProtectedApi;
|
24 | 26 | import software.amazon.awssdk.core.interceptor.Context;
|
25 | 27 | import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
|
26 | 28 | import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
|
27 | 29 | import software.amazon.awssdk.http.SdkHttpFullRequest;
|
| 30 | +import software.amazon.awssdk.services.s3.model.PutObjectRequest; |
| 31 | +import software.amazon.awssdk.services.s3.model.UploadPartRequest; |
28 | 32 | import software.amazon.awssdk.utils.IoUtils;
|
29 | 33 | import software.amazon.awssdk.utils.Md5Utils;
|
30 | 34 |
|
31 | 35 | @SdkProtectedApi
|
32 | 36 | public class AddContentMd5HeaderInterceptor implements ExecutionInterceptor {
|
33 | 37 |
|
| 38 | + // List of operations that should be ignored by this interceptor. |
| 39 | + // These are costly operations, so adding the md5 header will take a performance hit |
| 40 | + private static final List<Class> BLACKLIST_METHODS = Arrays.asList(PutObjectRequest.class, UploadPartRequest.class); |
| 41 | + |
34 | 42 | @Override
|
35 | 43 | public SdkHttpFullRequest modifyHttpRequest(Context.ModifyHttpRequest context, ExecutionAttributes executionAttributes) {
|
36 | 44 | SdkHttpFullRequest request = context.httpRequest();
|
37 |
| - if (request.contentStreamProvider().isPresent() && !request.firstMatchingHeader(CONTENT_MD5).isPresent()) { |
| 45 | + |
| 46 | + if (!BLACKLIST_METHODS.contains(context.request().getClass()) && request.contentStreamProvider().isPresent() |
| 47 | + && !request.firstMatchingHeader(CONTENT_MD5).isPresent()) { |
| 48 | + |
38 | 49 | try {
|
39 | 50 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
40 | 51 | IoUtils.copy(request.contentStreamProvider().get().newStream(), baos);
|
|
0 commit comments