21
21
import java .util .List ;
22
22
import java .util .Locale ;
23
23
import java .util .Optional ;
24
- import java .util .function .Supplier ;
25
24
import software .amazon .awssdk .annotations .SdkInternalApi ;
26
25
import software .amazon .awssdk .core .RequestCompressionConfiguration ;
27
26
import software .amazon .awssdk .core .RequestOverrideConfiguration ;
28
27
import software .amazon .awssdk .core .SdkBytes ;
29
- import software .amazon .awssdk .core .SdkSystemSetting ;
30
28
import software .amazon .awssdk .core .exception .SdkClientException ;
31
29
import software .amazon .awssdk .core .interceptor .ExecutionAttributes ;
32
30
import software .amazon .awssdk .core .interceptor .SdkExecutionAttribute ;
37
35
import software .amazon .awssdk .core .internal .http .pipeline .MutableRequestToRequestPipeline ;
38
36
import software .amazon .awssdk .http .ContentStreamProvider ;
39
37
import software .amazon .awssdk .http .SdkHttpFullRequest ;
40
- import software .amazon .awssdk .profiles .ProfileFile ;
41
- import software .amazon .awssdk .profiles .ProfileFileSystemSetting ;
42
- import software .amazon .awssdk .profiles .ProfileProperty ;
43
38
import software .amazon .awssdk .utils .IoUtils ;
44
39
45
40
/**
49
44
public class CompressRequestStage implements MutableRequestToRequestPipeline {
50
45
private static final int DEFAULT_MIN_COMPRESSION_SIZE = 10_240 ;
51
46
private static final int MIN_COMPRESSION_SIZE_LIMIT = 10_485_760 ;
52
- private static final Supplier <ProfileFile > PROFILE_FILE = ProfileFile ::defaultProfileFile ;
53
- private static final String PROFILE_NAME = ProfileFileSystemSetting .AWS_PROFILE .getStringValueOrThrow ();
54
- private static Boolean compressionEnabledClientLevel ;
55
- private static Boolean compressionEnabledEnvLevel ;
56
- private static Boolean compressionEnabledProfileLevel ;
57
- private static int minCompressionSizeClientLevel = -1 ;
58
- private static int minCompressionSizeEnvLevel = -1 ;
59
- private static int minCompressionSizeProfileLevel = -1 ;
60
-
61
47
62
48
@ Override
63
49
public SdkHttpFullRequest .Builder execute (SdkHttpFullRequest .Builder input , RequestExecutionContext context )
@@ -153,36 +139,11 @@ private static boolean resolveRequestCompressionEnabled(RequestExecutionContext
153
139
return requestCompressionEnabledRequestLevel .get ();
154
140
}
155
141
156
- if (compressionEnabledClientLevel != null ) {
157
- return compressionEnabledClientLevel ;
158
- }
159
- if (context .executionAttributes ().getAttribute (SdkExecutionAttribute .REQUEST_COMPRESSION_CONFIGURATION ) != null ) {
160
- Boolean requestCompressionEnabledClientLevel = context .executionAttributes ().getAttribute (
161
- SdkExecutionAttribute .REQUEST_COMPRESSION_CONFIGURATION ).requestCompressionEnabled ();
162
- if (requestCompressionEnabledClientLevel != null ) {
163
- compressionEnabledClientLevel = requestCompressionEnabledClientLevel ;
164
- return compressionEnabledClientLevel ;
165
- }
166
- }
167
-
168
- if (compressionEnabledEnvLevel != null ) {
169
- return compressionEnabledEnvLevel ;
170
- }
171
- if (SdkSystemSetting .AWS_DISABLE_REQUEST_COMPRESSION .getBooleanValue ().isPresent ()) {
172
- compressionEnabledEnvLevel = !SdkSystemSetting .AWS_DISABLE_REQUEST_COMPRESSION .getBooleanValue ().get ();
173
- return compressionEnabledEnvLevel ;
174
- }
175
-
176
- if (compressionEnabledProfileLevel != null ) {
177
- return compressionEnabledProfileLevel ;
178
- }
179
- Optional <Boolean > profileSetting =
180
- PROFILE_FILE .get ()
181
- .profile (PROFILE_NAME )
182
- .flatMap (p -> p .booleanProperty (ProfileProperty .DISABLE_REQUEST_COMPRESSION ));
183
- if (profileSetting .isPresent ()) {
184
- compressionEnabledProfileLevel = !profileSetting .get ();
185
- return compressionEnabledProfileLevel ;
142
+ Boolean isEnabled = context .executionAttributes ()
143
+ .getAttribute (SdkExecutionAttribute .REQUEST_COMPRESSION_CONFIGURATION )
144
+ .requestCompressionEnabled ();
145
+ if (isEnabled != null ) {
146
+ return isEnabled ;
186
147
}
187
148
188
149
return true ;
@@ -205,38 +166,11 @@ private static int resolveMinCompressionSize(RequestExecutionContext context) {
205
166
return minimumCompressionSizeRequestLevel .get ();
206
167
}
207
168
208
- if (minCompressionSizeClientLevel >= 0 ) {
209
- return minCompressionSizeClientLevel ;
210
- }
211
- if (context .executionAttributes ().getAttribute (SdkExecutionAttribute .REQUEST_COMPRESSION_CONFIGURATION ) != null ) {
212
- Integer minimumCompressionSizeClientLevel =
213
- context .executionAttributes ()
214
- .getAttribute (SdkExecutionAttribute .REQUEST_COMPRESSION_CONFIGURATION )
215
- .minimumCompressionThresholdInBytes ();
216
- if (minimumCompressionSizeClientLevel != null ) {
217
- minCompressionSizeClientLevel = minimumCompressionSizeClientLevel ;
218
- return minCompressionSizeClientLevel ;
219
- }
220
- }
221
-
222
- if (minCompressionSizeEnvLevel >= 0 ) {
223
- return minCompressionSizeEnvLevel ;
224
- }
225
- if (SdkSystemSetting .AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTES .getIntegerValue ().isPresent ()) {
226
- minCompressionSizeEnvLevel = SdkSystemSetting .AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTES .getIntegerValue ().get ();
227
- return minCompressionSizeEnvLevel ;
228
- }
229
-
230
- if (minCompressionSizeProfileLevel >= 0 ) {
231
- return minCompressionSizeProfileLevel ;
232
- }
233
- Optional <String > profileSetting =
234
- PROFILE_FILE .get ()
235
- .profile (PROFILE_NAME )
236
- .flatMap (p -> p .property (ProfileProperty .REQUEST_MIN_COMPRESSION_SIZE_BYTES ));
237
- if (profileSetting .isPresent ()) {
238
- minCompressionSizeProfileLevel = Integer .parseInt (profileSetting .get ());
239
- return minCompressionSizeProfileLevel ;
169
+ Integer threshold = context .executionAttributes ()
170
+ .getAttribute (SdkExecutionAttribute .REQUEST_COMPRESSION_CONFIGURATION )
171
+ .minimumCompressionThresholdInBytes ();
172
+ if (threshold != null ) {
173
+ return threshold ;
240
174
}
241
175
242
176
return DEFAULT_MIN_COMPRESSION_SIZE ;
0 commit comments