diff --git a/Changelog.md b/Changelog.md index 72f34d2..b2be973 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,10 @@ - Fix JSON parsing of empty OCS results: the API serializes empty collections as `[]` instead of `{}`, which caused a `MismatchedInputException` when e.g. listing users or groups on an empty result (issue #112) +- Fix file uploads (and other WebDAV writes) failing on servers running on a + non-standard port: preemptive authentication now uses the configured port, so + the server no longer issues an auth challenge that a streamed upload cannot + retry (issue #112) - Testing: integration tests can now auto-provision a throw-away Nextcloud server via Testcontainers when Docker is available, and are executed in CI (GitHub Actions) diff --git a/src/main/java/org/aarboard/nextcloud/api/webdav/AWebdavHandler.java b/src/main/java/org/aarboard/nextcloud/api/webdav/AWebdavHandler.java index b1f32b2..98c0f56 100644 --- a/src/main/java/org/aarboard/nextcloud/api/webdav/AWebdavHandler.java +++ b/src/main/java/org/aarboard/nextcloud/api/webdav/AWebdavHandler.java @@ -179,7 +179,13 @@ protected Sardine buildAuthSardine() Sardine sardine = SardineFactory.begin(); sardine.setCredentials(this.serverConfig.getUserName(), this.serverConfig.getAuthenticationConfig().getPassword()); - sardine.enablePreemptiveAuthentication(this.serverConfig.getServerName()); + // Pass the configured port so preemptive authentication also applies + // on non-standard ports (e.g. behind a reverse proxy). Without it the + // hostname-only overload assumes ports 80/443, the server then issues + // an auth challenge, and non-repeatable requests such as a streamed + // file upload (PUT) fail because they cannot be retried. + sardine.enablePreemptiveAuthentication(this.serverConfig.getServerName(), + this.serverConfig.getPort(), this.serverConfig.getPort()); return sardine; } return new SardineImpl(this.serverConfig.getAuthenticationConfig().getBearerToken());