From 3fe72e3f7ffb798fb40655191ee72e93cdfa07c3 Mon Sep 17 00:00:00 2001 From: Arturo Bernal Date: Sat, 19 Sep 2026 11:55:19 +0200 Subject: [PATCH] Preserve idle timeout when copying connection configuration --- .../client5/http/config/ConnectionConfig.java | 1 + .../http/config/TestConnectionConfigCopy.java | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 httpclient5/src/test/java/org/apache/hc/client5/http/config/TestConnectionConfigCopy.java diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/config/ConnectionConfig.java b/httpclient5/src/main/java/org/apache/hc/client5/http/config/ConnectionConfig.java index d69949f1a4..16b36f766a 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/config/ConnectionConfig.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/config/ConnectionConfig.java @@ -181,6 +181,7 @@ public static ConnectionConfig.Builder copy(final ConnectionConfig config) { return new Builder() .setConnectTimeout(config.getConnectTimeout()) .setSocketTimeout(config.getSocketTimeout()) + .setIdleTimeout(config.getIdleTimeout()) .setValidateAfterInactivity(config.getValidateAfterInactivity()) .setTimeToLive(config.getTimeToLive()); } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestConnectionConfigCopy.java b/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestConnectionConfigCopy.java new file mode 100644 index 0000000000..c0f25b5a6b --- /dev/null +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestConnectionConfigCopy.java @@ -0,0 +1,48 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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 + * + * http://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. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ +package org.apache.hc.client5.http.config; + +import org.apache.hc.core5.util.Timeout; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class TestConnectionConfigCopy { + + @Test + void testCopyPreservesIdleTimeout() { + final Timeout idleTimeout = Timeout.ofSeconds(42); + + final ConnectionConfig original = ConnectionConfig.custom() + .setIdleTimeout(idleTimeout) + .build(); + + final ConnectionConfig copy = ConnectionConfig.copy(original).build(); + + Assertions.assertEquals(idleTimeout, copy.getIdleTimeout()); + } + +}