Skip to content

Commit da6414e

Browse files
committed
closed
1 parent 6b0ee2b commit da6414e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

http-client/src/main/java/io/avaje/http/client/DHttpClientContext.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ final class DHttpClientContext implements HttpClient, SpiHttpClient {
5050
private final LongAccumulator metricResMaxMicros = new LongAccumulator(Math::max, 0);
5151
private final Function<HttpException, RuntimeException> errorHandler;
5252

53+
private boolean closed;
54+
5355
DHttpClientContext(
5456
java.net.http.HttpClient httpClient,
5557
String baseUrl,
@@ -86,6 +88,11 @@ public <T> T create(Class<T> clientInterface, ClassLoader classLoader) {
8688

8789
@Override
8890
public HttpClientRequest request() {
91+
92+
if (closed) {
93+
throw new IllegalStateException("HttpClient is closed");
94+
}
95+
8996
return retryHandler == null
9097
? new DHttpClientRequest(this, requestTimeout)
9198
: new DHttpClientRequestWithRetry(this, requestTimeout, retryHandler);
@@ -389,6 +396,7 @@ String maxResponseBody(String body) {
389396

390397
@Override
391398
public void close() {
399+
this.closed = true;
392400
if (Integer.getInteger("java.specification.version") >= 21) {
393401
try {
394402
MethodHandles.lookup()

0 commit comments

Comments
 (0)