mirror of https://github.com/shred/acme4j
Control gzip compression via system property
parent
b7d17f3fba
commit
af9f236f90
|
@ -17,8 +17,10 @@ import java.net.Authenticator;
|
|||
import java.net.ProxySelector;
|
||||
import java.net.http.HttpClient;
|
||||
import java.time.Duration;
|
||||
import java.util.Optional;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.Nullable;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Contains network settings to be used for network connections.
|
||||
|
@ -27,11 +29,28 @@ import edu.umd.cs.findbugs.annotations.Nullable;
|
|||
*/
|
||||
public class NetworkSettings {
|
||||
|
||||
/**
|
||||
* Name of the system property to control GZIP compression. Expects a boolean value.
|
||||
*/
|
||||
public static final String GZIP_PROPERTY_NAME = "org.shredzone.acme4j.gzip_compression";
|
||||
|
||||
private ProxySelector proxySelector = HttpClient.Builder.NO_PROXY;
|
||||
private Duration timeout = Duration.ofSeconds(10);
|
||||
private @Nullable Authenticator authenticator = null;
|
||||
private boolean compression = true;
|
||||
|
||||
public NetworkSettings() {
|
||||
try {
|
||||
Optional.ofNullable(System.getProperty(GZIP_PROPERTY_NAME))
|
||||
.map(Boolean::parseBoolean)
|
||||
.ifPresent(val -> compression = val);
|
||||
} catch (Exception ex) {
|
||||
// Ignore a broken property name or a SecurityException
|
||||
LoggerFactory.getLogger(NetworkSettings.class)
|
||||
.warn("Could not read system property: {}", GZIP_PROPERTY_NAME, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link ProxySelector} to be used for connections.
|
||||
*
|
||||
|
@ -104,6 +123,9 @@ public class NetworkSettings {
|
|||
/**
|
||||
* Sets if HTTP compression is enabled. It is enabled by default, but can be
|
||||
* disabled e.g. for debugging purposes.
|
||||
* <p>
|
||||
* acme4j gzip compression can also be controlled via the {@value #GZIP_PROPERTY_NAME}
|
||||
* system property.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
|
|
@ -74,4 +74,27 @@ public class NetworkSettingsTest {
|
|||
"timeout accepted negative duration");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSystemProperty() {
|
||||
assertThat(NetworkSettings.GZIP_PROPERTY_NAME)
|
||||
.startsWith("org.shredzone.acme4j")
|
||||
.contains("gzip");
|
||||
|
||||
System.clearProperty(NetworkSettings.GZIP_PROPERTY_NAME);
|
||||
var settingsNone = new NetworkSettings();
|
||||
assertThat(settingsNone.isCompressionEnabled()).isTrue();
|
||||
|
||||
System.setProperty(NetworkSettings.GZIP_PROPERTY_NAME, "true");
|
||||
var settingsTrue = new NetworkSettings();
|
||||
assertThat(settingsTrue.isCompressionEnabled()).isTrue();
|
||||
|
||||
System.setProperty(NetworkSettings.GZIP_PROPERTY_NAME, "false");
|
||||
var settingsFalse = new NetworkSettings();
|
||||
assertThat(settingsFalse.isCompressionEnabled()).isFalse();
|
||||
|
||||
System.setProperty(NetworkSettings.GZIP_PROPERTY_NAME, "1234");
|
||||
var settingsNonBoolean = new NetworkSettings();
|
||||
assertThat(settingsNonBoolean.isCompressionEnabled()).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ What you might also need to know:
|
|||
- A new `AcmeNotSupportedException` is thrown if a feature is not supported by the server. It is a subclass of the `AcmeProtocolException` runtime exception.
|
||||
- Starting with _acme4j_ v3, we will require the smallest Java SE LTS version that is still receiving premier support according to the [Oracle Java SE Support Roadmap](https://www.oracle.com/java/technologies/java-se-support-roadmap.html). At the time of writing, these are Java 11 and Java 17, so _acme4j_ requires Java 11 starting from now. With the prospected release of Java 21 (LTS) in September 2023, we will start to require Java 17, and so on. If you still need Java 8, you can use _acme4j_ v2, which will still receive security bugfixes until end of 2023.
|
||||
- _acme4j_ now uses the new `java.net.http` client. Due to limitations of the API, HTTP errors are only thrown with the error code, but the respective error message is missing. If you checked the error message in your unit tests, be prepared that they might fail now.
|
||||
- acme4j now accepts HTTP gzip compression. It is enabled by default, but can be disabled in the `NetworkSettings` if it should cause problems or impedes debugging.
|
||||
- acme4j now accepts HTTP gzip compression. It is enabled by default, but if it causes problems or impedes debugging, it can be disabled in the `NetworkSettings` or by setting the `org.shredzone.acme4j.gzip_compression` system property to `false`.
|
||||
- All deprecated methods have been removed.
|
||||
|
||||
## Migration to Version 2.16
|
||||
|
|
Loading…
Reference in New Issue