Skip to content

Commit 77210eb

Browse files
committed
add a better warning javadoc
1 parent 236aac3 commit 77210eb

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

httpclient5/src/main/java/org/apache/hc/client5/http/config/EnvironmentProxyConfigurer.java

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,72 +39,70 @@
3939
* <h2>EnvironmentProxyConfigurer</h2>
4040
*
4141
* <p>
42-
* Many *nix shells, container runtimes, and CI systems advertise an
43-
* outbound HTTP proxy exclusively via the environment variables
44-
* {@code HTTP_PROXY}, {@code HTTPS_PROXY}, and {@code NO_PROXY}.
45-
* The JDK, however, expects the corresponding <em>system-properties</em>
46-
* &nbsp;({@code http.proxyHost}, {@code http.proxyPort}, &hellip;) when it
47-
* resolves a proxy through {@link java.net.ProxySelector} or performs
48-
* authentication through {@link java.net.Authenticator}.
42+
* Many *nix shells, container runtimes, and CI systems expose an outbound
43+
* proxy exclusively via the environment variables {@code HTTP_PROXY},
44+
* {@code HTTPS_PROXY}, and {@code NO_PROXY}. The JDK, however, expects the
45+
* equivalent <em>system&nbsp;properties</em>
46+
* ({@code http.proxyHost}, {@code http.proxyPort}, &amp;c.) when it resolves a
47+
* proxy through {@link java.net.ProxySelector} or performs authentication via
48+
* {@link java.net.Authenticator}.
4949
* </p>
5050
*
5151
* <p>
5252
* <strong>EnvironmentProxyConfigurer</strong> is a small, <em>opt-in</em>
53-
* utility that copies the commonly-used variables to the standard
54-
* properties once, at application start-up. It is <em>not</em> invoked
55-
* automatically by HttpClient – call it explicitly if you want this
56-
* behaviour:
53+
* helper that copies those variables to the standard properties once, at
54+
* application start-up. <strong>It is <em>not</em> invoked automatically by
55+
* HttpClient.</strong> Call it explicitly if you want the mapping:
5756
* </p>
5857
*
5958
* <pre>{@code
60-
* public static void main(String[] args) {
61-
* EnvironmentProxyConfigurer.apply(); // one-liner
62-
* CloseableHttpClient client = HttpClientBuilder.create()
63-
* .useSystemProperties() // default behaviour
64-
* .build();
65-
* …
66-
* }
59+
* EnvironmentProxyConfigurer.apply(); // one-liner
60+
* CloseableHttpClient client = HttpClientBuilder.create()
61+
* .useSystemProperties() // default behaviour
62+
* .build();
6763
* }</pre>
6864
*
6965
* <h3>Mapping rules</h3>
7066
* <ul>
71-
* <li>{@code HTTP_PROXY} &rarr; {@code http.proxyHost},
67+
* <li>{@code HTTP_PROXY} {@code http.proxyHost},
7268
* {@code http.proxyPort}, {@code http.proxyUser},
7369
* {@code http.proxyPassword}</li>
74-
* <li>{@code HTTPS_PROXY} &rarr; {@code https.proxyHost},
70+
* <li>{@code HTTPS_PROXY} {@code https.proxyHost},
7571
* {@code https.proxyPort}, {@code https.proxyUser},
7672
* {@code https.proxyPassword}</li>
77-
* <li>{@code NO_PROXY} &rarr; {@code http.nonProxyHosts},
78-
* {@code https.nonProxyHosts} &nbsp;(commas are converted to the
79-
* pipe&nbsp;‘|’ separator required by the JDK)</li>
73+
* <li>{@code NO_PROXY} {@code http.nonProxyHosts},
74+
* {@code https.nonProxyHosts}&nbsp; (commas are converted to the
75+
* ‘|’ separator required by the JDK)</li>
8076
* <li>Lower-case aliases ({@code http_proxy}, {@code https_proxy},
8177
* {@code no_proxy}) are recognised as well.</li>
8278
* </ul>
8379
*
8480
* <h3>Design notes</h3>
8581
* <ul>
8682
* <li><strong>Idempotent:</strong> if a target property is already set
87-
* (for example with {@code -Dhttp.proxyHost=…}) it is left
88-
* untouched.</li>
83+
* (e.g.&nbsp;via {@code -Dhttp.proxyHost=…}) it is left untouched.</li>
8984
* <li><strong>Thread-safe:</strong> all reads and writes are wrapped in
9085
* {@code AccessController.doPrivileged} and synchronise only on the
9186
* global {@link System} properties map.</li>
92-
* <li><strong>No side-effects unless invoked:</strong> because the
93-
* method is <em>not</em> called from within
94-
* {@link org.apache.hc.client5.http.impl.classic.HttpClientBuilder},
95-
* applications that do not need proxy support see no change in
96-
* JVM-wide state.</li>
9787
* </ul>
9888
*
89+
* <h3>Warning</h3>
9990
* <p>
100-
* The class is {@linkplain org.apache.hc.core5.annotation.Contract
101-
* stateless} and safe to call multiple times; subsequent invocations will
102-
* be no-ops after the first successful copy.
91+
* Calling {@link #apply()} changes JVM-wide system properties. The new proxy
92+
* settings therefore apply to <em>all</em> libraries and threads in the same
93+
* process. Invoke this method only if your application really needs to
94+
* inherit proxy configuration from the environment and you are aware that
95+
* other components may be affected.
96+
* </p>
97+
*
98+
* <p>
99+
* The class is {@linkplain org.apache.hc.core5.annotation.Contract stateless}
100+
* and safe to call multiple times; subsequent invocations are no-ops once the
101+
* copy has succeeded.
103102
* </p>
104103
*
105104
* @since 5.6
106105
*/
107-
108106
@Contract(threading = ThreadingBehavior.STATELESS)
109107
public final class EnvironmentProxyConfigurer {
110108

0 commit comments

Comments
 (0)