From f9fe96d3d70eb058531cd373173927ce324a3a1b Mon Sep 17 00:00:00 2001 From: David Kocher Date: Fri, 10 Jan 2025 13:30:12 +0100 Subject: [PATCH] Use default redirect strategy handling `PROPFIND` just fine. --- .../com/github/sardine/impl/SardineImpl.java | 14 ++--- .../sardine/impl/SardineRedirectStrategy.java | 51 ------------------- 2 files changed, 8 insertions(+), 57 deletions(-) delete mode 100644 src/main/java/com/github/sardine/impl/SardineRedirectStrategy.java diff --git a/src/main/java/com/github/sardine/impl/SardineImpl.java b/src/main/java/com/github/sardine/impl/SardineImpl.java index fdb887cc..54859943 100644 --- a/src/main/java/com/github/sardine/impl/SardineImpl.java +++ b/src/main/java/com/github/sardine/impl/SardineImpl.java @@ -35,6 +35,7 @@ import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.cookie.CookieSpecFactory; import org.apache.hc.client5.http.entity.GzipDecompressingEntity; +import org.apache.hc.client5.http.impl.DefaultRedirectStrategy; import org.apache.hc.client5.http.impl.DefaultSchemePortResolver; import org.apache.hc.client5.http.impl.auth.BasicAuthCache; import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider; @@ -47,6 +48,7 @@ import org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner; import org.apache.hc.client5.http.io.HttpClientConnectionManager; import org.apache.hc.client5.http.protocol.HttpClientContext; +import org.apache.hc.client5.http.protocol.RedirectStrategy; import org.apache.hc.client5.http.routing.HttpRoutePlanner; import org.apache.hc.client5.http.socket.ConnectionSocketFactory; import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory; @@ -1100,7 +1102,7 @@ protected T execute(HttpClientContext context, HttpUriRequestBase request, H Integer httpMajorVersion = (Integer) context.getAttribute(HTTP_MAJOR_VERSION); if (httpMajorVersion != null){ - request.setVersion(new ProtocolVersion("HTTP", httpMajorVersion, 0)); + request.setVersion(new ProtocolVersion("HTTP", httpMajorVersion, 0)); } HttpContext requestLocalContext = new BasicHttpContext(context); try @@ -1154,7 +1156,7 @@ protected HttpClientBuilder configure(ProxySelector selector, CredentialsProvide return HttpClients.custom() .setUserAgent("Sardine/" + version) .setDefaultCredentialsProvider(credentials) -// .setRedirectStrategy(this.createDefaultRedirectStrategy()) + .setRedirectStrategy(this.createDefaultRedirectStrategy()) .setDefaultRequestConfig(RequestConfig.custom() // Only selectively enable this for PUT but not all entity enclosing methods .setExpectContinueEnabled(false).build()) @@ -1167,10 +1169,10 @@ protected DefaultSchemePortResolver createDefaultSchemePortResolver() return new DefaultSchemePortResolver(); } -// protected SardineRedirectStrategy createDefaultRedirectStrategy() -// { -// return new SardineRedirectStrategy(); -// } + protected RedirectStrategy createDefaultRedirectStrategy() + { + return new DefaultRedirectStrategy(); + } /** * Creates a new registry for default ports with socket factories. diff --git a/src/main/java/com/github/sardine/impl/SardineRedirectStrategy.java b/src/main/java/com/github/sardine/impl/SardineRedirectStrategy.java deleted file mode 100644 index 6b0cc727..00000000 --- a/src/main/java/com/github/sardine/impl/SardineRedirectStrategy.java +++ /dev/null @@ -1,51 +0,0 @@ -///* -// * Copyright 2009-2011 Jon Stevens et al. -// * -// * Licensed 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. -// */ -// -//package com.github.sardine.impl; -// -//import java.net.URI; -// -//import org.apache.hc.client5.http.impl.DefaultRedirectStrategy; -//import org.apache.hc.client5.http.protocol.RedirectStrategy; -//import org.apache.hc.core5.http.HttpRequest; -//import org.apache.hc.core5.http.HttpResponse; -//import org.apache.hc.core5.http.ProtocolException; -//import org.apache.hc.core5.http.protocol.HttpContext; -// -//import com.github.sardine.impl.methods.HttpPropFind; -// -//public class SardineRedirectStrategy implements RedirectStrategy { -// -// @Override -// public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) -// throws ProtocolException { -// String method = request.getMethod(); -// if (DefaultRedirectStrategy.INSTANCE.isRedirected(request, response, context)) { -// return true; -// } -// return method.equalsIgnoreCase(HttpPropFind.METHOD_NAME); -// } -// -// @Override -// public URI getLocationURI(HttpRequest request, HttpResponse response, HttpContext context) { -// try { -// return DefaultRedirectStrategy.INSTANCE.getLocationURI(request, response, context); -// } catch (Exception e) { -// throw new RuntimeException(); -// } -// } -// -//}