diff --git a/core/src/main/java/com/linecorp/armeria/client/DefaultRequestExecution.java b/core/src/main/java/com/linecorp/armeria/client/DefaultRequestExecution.java deleted file mode 100644 index 5348861cb33..00000000000 --- a/core/src/main/java/com/linecorp/armeria/client/DefaultRequestExecution.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2024 LINE Corporation - * - * LINE Corporation licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package com.linecorp.armeria.client; - -final class DefaultRequestExecution implements RequestExecution { - - private final ClientRequestContext ctx; - - DefaultRequestExecution(ClientRequestContext ctx) { - this.ctx = ctx; - } - - @Override - public ClientRequestContext ctx() { - return ctx; - } -} diff --git a/core/src/main/java/com/linecorp/armeria/client/RequestExecution.java b/core/src/main/java/com/linecorp/armeria/client/RequestExecution.java index eff03b2e43d..d82e12b26e3 100644 --- a/core/src/main/java/com/linecorp/armeria/client/RequestExecution.java +++ b/core/src/main/java/com/linecorp/armeria/client/RequestExecution.java @@ -32,7 +32,9 @@ public interface RequestExecution { * TBU. */ static RequestExecution of(ClientRequestContext ctx) { - return new DefaultRequestExecution(ctx); + final ClientRequestContextExtension ctxExt = ctx.as(ClientRequestContextExtension.class); + checkArgument(ctxExt != null, "ctx (%s) should be created from 'ClientRequestContextBuilder'", ctx); + return ctxExt; } /** diff --git a/core/src/main/java/com/linecorp/armeria/internal/client/ClientRequestContextExtension.java b/core/src/main/java/com/linecorp/armeria/internal/client/ClientRequestContextExtension.java index 0784f96211e..a9531795165 100644 --- a/core/src/main/java/com/linecorp/armeria/internal/client/ClientRequestContextExtension.java +++ b/core/src/main/java/com/linecorp/armeria/internal/client/ClientRequestContextExtension.java @@ -18,10 +18,14 @@ import java.util.concurrent.CompletableFuture; +import com.linecorp.armeria.client.Client; import com.linecorp.armeria.client.ClientRequestContext; +import com.linecorp.armeria.client.RequestExecution; import com.linecorp.armeria.client.endpoint.EndpointGroup; import com.linecorp.armeria.common.HttpHeaderNames; import com.linecorp.armeria.common.HttpHeaders; +import com.linecorp.armeria.common.Request; +import com.linecorp.armeria.common.Response; import com.linecorp.armeria.common.logging.RequestLog; import com.linecorp.armeria.internal.common.CancellationScheduler; import com.linecorp.armeria.internal.common.RequestContextExtension; @@ -30,7 +34,8 @@ * This class exposes extension methods for {@link ClientRequestContext} * which are used internally by Armeria but aren't intended for public usage. */ -public interface ClientRequestContextExtension extends ClientRequestContext, RequestContextExtension { +public interface ClientRequestContextExtension extends ClientRequestContext, RequestContextExtension, + RequestExecution { /** * Returns the {@link CancellationScheduler} used to schedule a response timeout. @@ -75,4 +80,14 @@ public interface ClientRequestContextExtension extends ClientRequestContext, Req HttpHeaders internalRequestHeaders(); boolean initializationTriggered(); + + @Override + default ClientRequestContext ctx() { + return this; + } + + @Override + default O execute(Client delegate, I req) throws Exception { + return RequestExecution.super.execute(delegate, req); + } }