You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/09/06 21:43:34 UTC
[commons-vfs] branch master updated: VFS-787 - Allow users to set
proxy schemes like http/https (#122)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
The following commit(s) were added to refs/heads/master by this push:
new e4fd611 VFS-787 - Allow users to set proxy schemes like http/https (#122)
e4fd611 is described below
commit e4fd6117979e8dbe0482a2a48526691a03e1bd90
Author: satish-csi <67...@users.noreply.github.com>
AuthorDate: Mon Sep 7 03:13:26 2020 +0530
VFS-787 - Allow users to set proxy schemes like http/https (#122)
* VFS-787 - Allow users to set proxy schemes like http/https
* VFS-787 - Allow users to set proxy schemes like http/https - update review comments
* VFS-787 - test case covering proxy http scheme
* VFS-787 - update xdoc for extra parameter
* Update filesystems.xml
Fix alignment and typo.
Co-authored-by: Gary Gregory <ga...@users.noreply.github.com>
---
.../vfs2/provider/http4/Http4FileProvider.java | 3 +-
.../http4/Http4FileSystemConfigBuilder.java | 33 ++++++++++++++++++++
.../vfs2/provider/http5/Http5FileProvider.java | 3 +-
.../http5/Http5FileSystemConfigBuilder.java | 35 ++++++++++++++++++++++
.../http4/test/Http4GetContentInfoTest.java | 1 +
.../http5/test/Http5GetContentInfoTest.java | 1 +
src/site/xdoc/filesystems.xml | 1 +
7 files changed, 75 insertions(+), 2 deletions(-)
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java
index 09cc701..1a4eaf3 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java
@@ -335,9 +335,10 @@ public class Http4FileProvider extends AbstractOriginatingFileProvider {
final FileSystemOptions fileSystemOptions) {
final String proxyHost = builder.getProxyHost(fileSystemOptions);
final int proxyPort = builder.getProxyPort(fileSystemOptions);
+ final String proxyScheme = builder.getProxyScheme(fileSystemOptions);
if (proxyHost != null && proxyHost.length() > 0 && proxyPort > 0) {
- return new HttpHost(proxyHost, proxyPort);
+ return new HttpHost(proxyHost, proxyPort, proxyScheme);
}
return null;
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystemConfigBuilder.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystemConfigBuilder.java
index 4a26f27..717753c 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystemConfigBuilder.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileSystemConfigBuilder.java
@@ -20,6 +20,7 @@ import org.apache.commons.vfs2.FileSystem;
import org.apache.commons.vfs2.FileSystemConfigBuilder;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.UserAuthenticator;
+import org.apache.http.HttpHost;
import org.apache.http.cookie.Cookie;
/**
@@ -160,6 +161,14 @@ public class Http4FileSystemConfigBuilder extends FileSystemConfigBuilder {
private static final boolean DEFAULT_HOSTNAME_VERIFICATION_ENABLED = true;
/**
+ * Defines http scheme for proxy host
+ *<p>
+ *This parameter expects a value of type {@link String}.
+ *</p>
+ */
+ private static final String PROXY_SCHEME = "proxyScheme";
+
+ /**
* Construct an {@code Http4FileSystemConfigBuilder}.
*
* @param prefix String for properties of this file system.
@@ -228,6 +237,18 @@ public class Http4FileSystemConfigBuilder extends FileSystemConfigBuilder {
}
/**
+ * Sets the proxy-scheme to use for http connection. You have to set the ProxyHost too if you would like to have the
+ * proxy really used.
+ *
+ * @param opts The FileSystem options.
+ * @param proxyScheme the protocol scheme
+ * @see #setProxyHost
+ * @since 2.7.0
+ */
+ public void setProxyScheme(final FileSystemOptions opts, final String proxyScheme) {
+ setParam(opts, PROXY_SCHEME, proxyScheme);
+ }
+ /**
* Gets the proxy to use for http connection. You have to set the ProxyPort too if you would like to have the proxy
* really used.
*
@@ -252,6 +273,18 @@ public class Http4FileSystemConfigBuilder extends FileSystemConfigBuilder {
}
/**
+ * Gets the proxy-scheme to use for http the connection. You have to set the ProxyHost too if you would like to have
+ * the proxy really used.
+ *
+ * @param opts The FileSystem options.
+ * @return proxyScheme: the http/https scheme of proxy server
+ * @see #setProxyHost
+ * @since 2.7.0
+ */
+ public String getProxyScheme(final FileSystemOptions opts) {
+ return getString(opts, PROXY_SCHEME, HttpHost.DEFAULT_SCHEME_NAME);
+ }
+ /**
* Sets the proxy authenticator where the system should get the credentials from.
*
* @param opts The FileSystem options.
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileProvider.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileProvider.java
index 7295e6a..5c38d1b 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileProvider.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileProvider.java
@@ -344,11 +344,12 @@ public class Http5FileProvider extends AbstractOriginatingFileProvider {
private HttpHost getProxyHttpHost(final Http5FileSystemConfigBuilder builder,
final FileSystemOptions fileSystemOptions) {
+ final String proxyScheme = builder.getProxyScheme(fileSystemOptions);
final String proxyHost = builder.getProxyHost(fileSystemOptions);
final int proxyPort = builder.getProxyPort(fileSystemOptions);
if (proxyHost != null && proxyHost.length() > 0 && proxyPort > 0) {
- return new HttpHost(proxyHost, proxyPort);
+ return new HttpHost(proxyScheme, proxyHost, proxyPort);
}
return null;
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileSystemConfigBuilder.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileSystemConfigBuilder.java
index 4a0341c..406d0fd 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileSystemConfigBuilder.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileSystemConfigBuilder.java
@@ -21,6 +21,7 @@ import org.apache.commons.vfs2.FileSystemConfigBuilder;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.UserAuthenticator;
import org.apache.hc.client5.http.cookie.Cookie;
+import org.apache.hc.core5.http.HttpHost;
/**
* Configuration options builder utility for http5 provider.
@@ -112,6 +113,14 @@ public class Http5FileSystemConfigBuilder extends FileSystemConfigBuilder {
private static final String KEY_USER_AGENT = "userAgent";
/**
+ * Defines http scheme for proxy host
+ *<p>
+ *This parameter expects a value of type {@link String}.
+ *</p>
+ */
+ private static final String PROXY_SCHEME = "proxyScheme";
+
+ /**
* Defines whether the preemptive authentication should be enabled or not.
* <p>
* This parameter expects a value of type {@link Boolean}.
@@ -243,6 +252,19 @@ public class Http5FileSystemConfigBuilder extends FileSystemConfigBuilder {
}
/**
+ * Sets the proxy-scheme to use for http connection. You have to set the ProxyHost too if you would like to have the
+ * proxy really used.
+ *
+ * @param opts The FileSystem options.
+ * @param proxyScheme the protocol scheme
+ * @see #setProxyHost
+ * @since 2.7.0
+ */
+ public void setProxyScheme(final FileSystemOptions opts, final String proxyScheme) {
+ setParam(opts, PROXY_SCHEME, proxyScheme);
+ }
+
+ /**
* Gets the proxy to use for http connection. You have to set the ProxyPort too if you would like to have the proxy
* really used.
*
@@ -267,6 +289,19 @@ public class Http5FileSystemConfigBuilder extends FileSystemConfigBuilder {
}
/**
+ * Gets the proxy-scheme to use for http the connection. You have to set the ProxyHost too if you would like to have
+ * the proxy really used.
+ *
+ * @param opts The FileSystem options.
+ * @return proxyScheme: the http/https scheme of proxy server
+ * @see #setProxyHost
+ * @since 2.7.0
+ */
+ public String getProxyScheme(final FileSystemOptions opts) {
+ return getString(opts, PROXY_SCHEME, HttpHost.DEFAULT_SCHEME.getId());
+ }
+
+ /**
* Sets the proxy authenticator where the system should get the credentials from.
*
* @param opts The FileSystem options.
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4GetContentInfoTest.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4GetContentInfoTest.java
index 03d2c03..64781af 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4GetContentInfoTest.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/test/Http4GetContentInfoTest.java
@@ -73,6 +73,7 @@ public class Http4GetContentInfoTest extends TestCase {
final FileSystemOptions opts = new FileSystemOptions();
builder.setProxyHost(opts, proxyHost);
builder.setProxyPort(opts, proxyPort);
+ builder.setProxyScheme(opts, "http");
return opts;
}
}
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5GetContentInfoTest.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5GetContentInfoTest.java
index 301c3a9..25bc39e 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5GetContentInfoTest.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/test/Http5GetContentInfoTest.java
@@ -73,6 +73,7 @@ public class Http5GetContentInfoTest extends TestCase {
final FileSystemOptions opts = new FileSystemOptions();
builder.setProxyHost(opts, proxyHost);
builder.setProxyPort(opts, proxyPort);
+ builder.setProxyScheme(opts, "http");
return opts;
}
}
diff --git a/src/site/xdoc/filesystems.xml b/src/site/xdoc/filesystems.xml
index 71d2d8d..980970d 100644
--- a/src/site/xdoc/filesystems.xml
+++ b/src/site/xdoc/filesystems.xml
@@ -527,6 +527,7 @@
<ul>
<li><b>proxyHost</b> The proxy host to connect through.</li>
<li><b>proxyPort</b> The proxy port to use.</li>
+ <li><b>proxyScheme</b> The proxy scheme (http/https) to use.</li>
<li><b>cookies</b> An array of Cookies to add to the request.</li>
<li><b>maxConnectionsPerHost</b> The maximum number of connections allowed to
a specific host and port. The default is 5.</li>