This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
The following commit(s) were added to refs/heads/master by this push:
new 0a7d6369 [MRESOLVER-340] Make WebDAV "dance" disabled by default (#264)
0a7d6369 is described below
commit 0a7d6369ed2a7e37a6091b86accdb918fc872f22
Author: Tamas Cservenak <[email protected]>
AuthorDate: Tue Mar 7 11:13:51 2023 +0100
[MRESOLVER-340] Make WebDAV "dance" disabled by default (#264)
Vast majority of our users use MRMs and not some "repo server made out of
sticks" (like WebDAV server was the fashion in 2000s), but we still "tax"
majority of our users with "WebDAV dance".
Make it disabled by default, while those who really need it, still can it
enable, even per server.
---
https://issues.apache.org/jira/browse/MRESOLVER-340
---
.../aether/transport/http/HttpTransporter.java | 34 ++++++++++++----------
.../aether/transport/http/HttpTransporterTest.java | 9 ++++--
src/site/markdown/configuration.md | 1 +
3 files changed, 27 insertions(+), 17 deletions(-)
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 44b2eb5f..da56f33a 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
@@ -95,6 +95,8 @@ import static java.util.Objects.requireNonNull;
*/
final class HttpTransporter extends AbstractTransporter {
+ static final String SUPPORT_WEBDAV = "aether.connector.http.supportWebDav";
+
private static final Pattern CONTENT_RANGE_PATTERN =
Pattern.compile("\\s*bytes\\s+([0-9]+)\\s*-\\s*([0-9]+)\\s*/.*");
@@ -120,6 +122,8 @@ final class HttpTransporter extends AbstractTransporter {
private final boolean preemptiveAuth;
+ private final boolean supportWebDav;
+
HttpTransporter(
Map<String, ChecksumExtractor> checksumExtractors,
RemoteRepository repository,
@@ -164,6 +168,8 @@ final class HttpTransporter extends AbstractTransporter {
ConfigurationProperties.DEFAULT_HTTP_PREEMPTIVE_AUTH,
ConfigurationProperties.HTTP_PREEMPTIVE_AUTH + "." +
repository.getId(),
ConfigurationProperties.HTTP_PREEMPTIVE_AUTH);
+ this.supportWebDav =
+ ConfigUtils.getBoolean(session, false, SUPPORT_WEBDAV + "." +
repository.getId(), SUPPORT_WEBDAV);
String credentialEncoding = ConfigUtils.getString(
session,
ConfigurationProperties.DEFAULT_HTTP_CREDENTIAL_ENCODING,
@@ -364,23 +370,21 @@ final class HttpTransporter extends AbstractTransporter {
if (preemptiveAuth) {
context.getAuthCache().put(server, new BasicScheme());
}
- boolean put =
HttpPut.METHOD_NAME.equalsIgnoreCase(request.getMethod());
- if (state.getWebDav() == null && (put || isPayloadPresent(request))) {
- HttpOptions req = commonHeaders(new HttpOptions(request.getURI()));
- try (CloseableHttpResponse response = client.execute(server, req,
context)) {
- state.setWebDav(isWebDav(response));
- EntityUtils.consumeQuietly(response.getEntity());
- } catch (IOException e) {
- LOGGER.debug("Failed to prepare HTTP context", e);
+ if (supportWebDav) {
+ boolean put =
HttpPut.METHOD_NAME.equalsIgnoreCase(request.getMethod());
+ if (state.getWebDav() == null && (put ||
isPayloadPresent(request))) {
+ HttpOptions req = commonHeaders(new
HttpOptions(request.getURI()));
+ try (CloseableHttpResponse response = client.execute(server,
req, context)) {
+ state.setWebDav(response.containsHeader(HttpHeaders.DAV));
+ EntityUtils.consumeQuietly(response.getEntity());
+ } catch (IOException e) {
+ LOGGER.debug("Failed to prepare HTTP context", e);
+ }
+ }
+ if (put && Boolean.TRUE.equals(state.getWebDav())) {
+ mkdirs(request.getURI(), context);
}
}
- if (put && Boolean.TRUE.equals(state.getWebDav())) {
- mkdirs(request.getURI(), context);
- }
- }
-
- private boolean isWebDav(CloseableHttpResponse response) {
- return response.containsHeader(HttpHeaders.DAV);
}
@SuppressWarnings("checkstyle:magicnumber")
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 9f2d3c5f..bcba729d 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
@@ -668,6 +668,8 @@ public class HttpTransporterTest {
@Test
public void testPut_Authenticated_ExpectContinueBroken() throws Exception {
+ // this makes OPTIONS recover, and have only 1 PUT (startedCount=1 as
OPTIONS is not counted)
+ session.setConfigProperty(HttpTransporter.SUPPORT_WEBDAV, true);
httpServer.setAuthentication("testuser", "testpass");
httpServer.setExpectSupport(HttpServer.ExpectContinue.BROKEN);
auth = new AuthenticationBuilder()
@@ -808,6 +810,9 @@ public class HttpTransporterTest {
@Test
public void testPut_WebDav() throws Exception {
httpServer.setWebDav(true);
+ session.setConfigProperty(HttpTransporter.SUPPORT_WEBDAV, true);
+ newTransporter(httpServer.getHttpUrl());
+
RecordingTransportListener listener = new RecordingTransportListener();
PutTask task = new PutTask(URI.create("repo/dir1/dir2/file.txt"))
.setListener(listener)
@@ -915,7 +920,7 @@ public class HttpTransporterTest {
newTransporter(httpServer.getHttpUrl());
PutTask task = new
PutTask(URI.create("repo/file.txt")).setDataString("upload");
transporter.put(task);
- assertEquals(3, httpServer.getLogEntries().size()); // options
(challenged) + options w/ auth + put w/ auth
+ assertEquals(2, httpServer.getLogEntries().size()); // put
(challenged) + put w/ auth
httpServer.getLogEntries().clear();
task = new
PutTask(URI.create("repo/file.txt")).setDataString("upload");
transporter.put(task);
@@ -933,7 +938,7 @@ public class HttpTransporterTest {
newTransporter(httpServer.getHttpUrl());
PutTask task = new
PutTask(URI.create("repo/file.txt")).setDataString("upload");
transporter.put(task);
- assertEquals(2, httpServer.getLogEntries().size()); // options w/ auth
+ put w/ auth
+ assertEquals(1, httpServer.getLogEntries().size()); // put w/ auth
httpServer.getLogEntries().clear();
task = new
PutTask(URI.create("repo/file.txt")).setDataString("upload");
transporter.put(task);
diff --git a/src/site/markdown/configuration.md
b/src/site/markdown/configuration.md
index 615b7121..8f13f059 100644
--- a/src/site/markdown/configuration.md
+++ b/src/site/markdown/configuration.md
@@ -39,6 +39,7 @@ Option | Type | Description | Default Value | Supports Repo
ID Suffix
`aether.connector.http.headers` | `Map<String, String>` | 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.preemptiveAuth` | boolean | Should HTTP client use
preemptive-authentication (works only w/ BASIC) or not. | `false` | yes
`aether.connector.http.retryHandler.count` | int | The maximum number of times
a request to a remote HTTP server should be retried in case of an error. | `3`
| yes
+`aether.connector.http.supportWebDav` | boolean | If enabled, transport makes
best effort to deploy to WebDAV server. This mode is not recommended, better
use real Maven Repository Manager instead. | `false` | yes
`aether.connector.https.cipherSuites` | String | Comma-separated list of
[Cipher
Suites](https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#ciphersuites)
which are enabled for HTTPS connections. | - (no restriction) | no
`aether.connector.https.securityMode` | String | Using this flag resolver may
set the "security mode" of HTTPS connector. Any other mode than 'default' is
NOT MEANT for production, as it is inherently not secure. Accepted values:
"default", "insecure" (ignore any kind of certificate validation errors and
hostname validation checks). | `"default"` | yes
`aether.connector.https.protocols` | String | Comma-separated list of
[Protocols](https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#jssenames)
which are enabled for HTTPS connections. | - (no restriction) | no