Skip to content

Commit f1d0c8b

Browse files
authored
closed (#656)
1 parent 6b0ee2b commit f1d0c8b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

Lines changed: 6 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,9 @@ public <T> T create(Class<T> clientInterface, ClassLoader classLoader) {
8688

8789
@Override
8890
public HttpClientRequest request() {
91+
if (closed) {
92+
throw new IllegalStateException("HttpClient is closed");
93+
}
8994
return retryHandler == null
9095
? new DHttpClientRequest(this, requestTimeout)
9196
: new DHttpClientRequestWithRetry(this, requestTimeout, retryHandler);
@@ -389,6 +394,7 @@ String maxResponseBody(String body) {
389394

390395
@Override
391396
public void close() {
397+
this.closed = true;
392398
if (Integer.getInteger("java.specification.version") >= 21) {
393399
try {
394400
MethodHandles.lookup()

0 commit comments

Comments
 (0)