diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/ConfigurationProperties.java b/maven-resolver-api/src/main/java/org/eclipse/aether/ConfigurationProperties.java index a5519514d..6ef570ca5 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/ConfigurationProperties.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/ConfigurationProperties.java @@ -259,6 +259,22 @@ public final class ConfigurationProperties { */ public static final int DEFAULT_HTTP_MAX_CONNECTIONS_PER_ROUTE = 50; + /** + * Boolean flag should the HTTP transport use expect-continue handshake for PUT requests. Not all transport support + * this option. This option may be needed for some broken HTTP servers. + * + * @see #DEFAULT_HTTP_EXPECT_CONTINUE + * @since 1.9.17 + */ + public static final String HTTP_EXPECT_CONTINUE = PREFIX_CONNECTOR + "http.expectContinue"; + + /** + * Default value if {@link #HTTP_EXPECT_CONTINUE} is not set: {@code true}. + * + * @since 1.9.17 + */ + public static final boolean DEFAULT_HTTP_EXPECT_CONTINUE = true; + /** * The mode that sets HTTPS transport "security mode": to ignore any SSL errors (certificate validity checks, * hostname verification). The default value is {@link #HTTPS_SECURITY_MODE_DEFAULT}. diff --git a/maven-resolver-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java b/maven-resolver-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java index 870204747..f6ed915fc 100644 --- a/maven-resolver-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java +++ b/maven-resolver-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java @@ -323,6 +323,15 @@ final class HttpTransporter extends AbstractTransporter { builder.useSystemProperties(); } + final boolean expectContinue = ConfigUtils.getBoolean( + session, + ConfigurationProperties.DEFAULT_HTTP_EXPECT_CONTINUE, + ConfigurationProperties.HTTP_EXPECT_CONTINUE + "." + repository.getId(), + ConfigurationProperties.HTTP_EXPECT_CONTINUE); + if (expectContinue != ConfigurationProperties.DEFAULT_HTTP_EXPECT_CONTINUE) { + state.setExpectContinue(expectContinue); + } + final boolean reuseConnections = ConfigUtils.getBoolean( session, ConfigurationProperties.DEFAULT_HTTP_REUSE_CONNECTIONS, diff --git a/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java b/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java index 597b35787..5c0de84a9 100644 --- a/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java +++ b/maven-resolver-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java @@ -728,6 +728,27 @@ public void testPut_Authenticated_ExpectContinueRejected() throws Exception { assertEquals("upload", TestFileUtils.readString(new File(repoDir, "file.txt"))); } + @Test + public void testPut_Authenticated_ExpectContinueDisabled() throws Exception { + session.setConfigProperty(ConfigurationProperties.HTTP_EXPECT_CONTINUE, false); + httpServer.setAuthentication("testuser", "testpass"); + httpServer.setExpectSupport(HttpServer.ExpectContinue.FAIL); // if transport tries Expect/Continue explode + auth = new AuthenticationBuilder() + .addUsername("testuser") + .addPassword("testpass") + .build(); + newTransporter(httpServer.getHttpUrl()); + RecordingTransportListener listener = new RecordingTransportListener(); + PutTask task = + new PutTask(URI.create("repo/file.txt")).setListener(listener).setDataString("upload"); + transporter.put(task); + assertEquals(0L, listener.dataOffset); + assertEquals(6L, listener.dataLength); + assertEquals(1, listener.startedCount); // w/ expectContinue enabled would have here 2 + assertTrue("Count: " + listener.progressedCount, listener.progressedCount > 0); + assertEquals("upload", TestFileUtils.readString(new File(repoDir, "file.txt"))); + } + @Test public void testPut_Authenticated_ExpectContinueRejected_ExplicitlyConfiguredHeader() throws Exception { Map headers = new HashMap<>(); diff --git a/src/site/markdown/configuration.md b/src/site/markdown/configuration.md index fbee0a98e..982fd1f75 100644 --- a/src/site/markdown/configuration.md +++ b/src/site/markdown/configuration.md @@ -38,6 +38,7 @@ Option | Type | Description | Default Value | Supports Repo ID Suffix `aether.connector.http.cacheState` | boolean | Flag indicating whether a memory-based cache is used for user tokens, connection managers, expect continue requests and authentication schemes. | `true` | no `aether.connector.http.connectionMaxTtl` | int | Total time to live in seconds for an HTTP connection, after that time, the connection will be dropped (no matter for how long it was idle). | `300` | yes `aether.connector.http.credentialEncoding` | String | The encoding/charset to use when exchanging credentials with HTTP servers. | `"ISO-8859-1"` | yes +`aether.connector.http.expectContinue` | boolean | Whether to use expect/continue handshake during PUTs. Some broken HTTP servers needs this disabled. | `true` | yes `aether.connector.http.headers` | `Map` | The request headers to use for HTTP-based repository connectors. The headers are specified using a map of strings mapping a header name to its value. The repository-specific headers map is supposed to be complete, i.e. is not merged with the general headers map. | - | yes `aether.connector.http.maxConnectionsPerRoute` | int | The maximum concurrent connections per route HTTP client is allowed to use. | `50` | yes `aether.connector.http.preemptiveAuth` | boolean | Should HTTP client use preemptive-authentication for all HTTP verbs (works only w/ BASIC). By default is disabled, as it is considered less secure. | `false` | yes