Skip to content

Commit be5f1f5

Browse files
committed
Make request level overrides take precedence
1 parent 960f73a commit be5f1f5

File tree

2 files changed

+9
-15
lines changed
  • client/client-core/src

2 files changed

+9
-15
lines changed

client/client-core/src/main/java/software/amazon/smithy/java/client/core/Client.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,17 @@ protected <I extends SerializableStruct, O extends SerializableStruct> Completab
7878
) {
7979
ClientPipeline<?, ?> callPipeline = pipeline;
8080
IdentityResolvers callIdentityResolvers = identityResolvers;
81-
ClientConfig callConfig = config;
8281
ClientInterceptor callInterceptor = interceptor;
8382

84-
// Apply the given override before potentially applying interceptor based overrides.
85-
var needsRebuild = false;
83+
// First apply overrides from interceptors.
84+
ClientConfig callConfig = callInterceptor.modifyBeforeCall(new CallHook<>(operation, config, input));
85+
// Overrides given per/operation take precedence over interceptors.
8686
if (overrideConfig != null) {
87-
needsRebuild = true;
8887
callConfig = callConfig.withRequestOverride(overrideConfig);
89-
callInterceptor = ClientInterceptor.chain(callConfig.interceptors());
90-
}
91-
92-
var updatedConfig = callInterceptor.modifyBeforeCall(new CallHook<>(operation, callConfig, input));
93-
if (updatedConfig != callConfig) {
94-
needsRebuild = true;
95-
callConfig = updatedConfig;
9688
}
9789

98-
if (needsRebuild) {
90+
// Rebuild the pipeline, resolvers, etc if the config changed.
91+
if (callConfig != config) {
9992
callPipeline = ClientPipeline.of(callConfig.protocol(), callConfig.transport());
10093
callInterceptor = ClientInterceptor.chain(callConfig.interceptors());
10194
callIdentityResolvers = IdentityResolvers.of(callConfig.identityResolvers());

client/client-core/src/test/java/software/amazon/smithy/java/client/core/ClientTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void readBeforeExecution(InputHook<?, ?> hook) {
156156
}
157157

158158
@Test
159-
public void allowsInterceptorRequestOverridesOnOtherOverrides() throws URISyntaxException {
159+
public void requestOverridesPerCallTakePrecedence() throws URISyntaxException {
160160
var queue = new MockQueue();
161161
queue.enqueue(HttpResponse.builder().statusCode(200).build());
162162
var id = "abc";
@@ -169,8 +169,9 @@ public void allowsInterceptorRequestOverridesOnOtherOverrides() throws URISyntax
169169
.addPlugin(config -> config.addInterceptor(new ClientInterceptor() {
170170
@Override
171171
public ClientConfig modifyBeforeCall(CallHook<?, ?> hook) {
172+
// Note that the overrides given to the call itself will override interceptors.
172173
var override = RequestOverrideConfig.builder()
173-
.putConfig(CallContext.APPLICATION_ID, id)
174+
.putConfig(CallContext.APPLICATION_ID, "foo")
174175
.build();
175176
return hook.config().withRequestOverride(override);
176177
}
@@ -190,7 +191,7 @@ public void readBeforeExecution(InputHook<?, ?> hook) {
190191
Document.ofObject(new HashMap<>()),
191192
RequestOverrideConfig.builder()
192193
.putConfig(CallContext.API_CALL_TIMEOUT, Duration.ofMinutes(2))
193-
.putConfig(CallContext.APPLICATION_ID, "foo") // this will be overridden in the interceptor
194+
.putConfig(CallContext.APPLICATION_ID, id) // this will be take precedence
194195
.build());
195196
}
196197
}

0 commit comments

Comments
 (0)