|
39 | 39 | * <h2>EnvironmentProxyConfigurer</h2> |
40 | 40 | * |
41 | 41 | * <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 | | - * ({@code http.proxyHost}, {@code http.proxyPort}, …) 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 properties</em> |
| 46 | + * ({@code http.proxyHost}, {@code http.proxyPort}, &c.) when it resolves a |
| 47 | + * proxy through {@link java.net.ProxySelector} or performs authentication via |
| 48 | + * {@link java.net.Authenticator}. |
49 | 49 | * </p> |
50 | 50 | * |
51 | 51 | * <p> |
52 | 52 | * <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: |
57 | 56 | * </p> |
58 | 57 | * |
59 | 58 | * <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(); |
67 | 63 | * }</pre> |
68 | 64 | * |
69 | 65 | * <h3>Mapping rules</h3> |
70 | 66 | * <ul> |
71 | | - * <li>{@code HTTP_PROXY} → {@code http.proxyHost}, |
| 67 | + * <li>{@code HTTP_PROXY} → {@code http.proxyHost}, |
72 | 68 | * {@code http.proxyPort}, {@code http.proxyUser}, |
73 | 69 | * {@code http.proxyPassword}</li> |
74 | | - * <li>{@code HTTPS_PROXY} → {@code https.proxyHost}, |
| 70 | + * <li>{@code HTTPS_PROXY} → {@code https.proxyHost}, |
75 | 71 | * {@code https.proxyPort}, {@code https.proxyUser}, |
76 | 72 | * {@code https.proxyPassword}</li> |
77 | | - * <li>{@code NO_PROXY} → {@code http.nonProxyHosts}, |
78 | | - * {@code https.nonProxyHosts} (commas are converted to the |
79 | | - * pipe ‘|’ separator required by the JDK)</li> |
| 73 | + * <li>{@code NO_PROXY} → {@code http.nonProxyHosts}, |
| 74 | + * {@code https.nonProxyHosts} (commas are converted to the |
| 75 | + * ‘|’ separator required by the JDK)</li> |
80 | 76 | * <li>Lower-case aliases ({@code http_proxy}, {@code https_proxy}, |
81 | 77 | * {@code no_proxy}) are recognised as well.</li> |
82 | 78 | * </ul> |
83 | 79 | * |
84 | 80 | * <h3>Design notes</h3> |
85 | 81 | * <ul> |
86 | 82 | * <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. via {@code -Dhttp.proxyHost=…}) it is left untouched.</li> |
89 | 84 | * <li><strong>Thread-safe:</strong> all reads and writes are wrapped in |
90 | 85 | * {@code AccessController.doPrivileged} and synchronise only on the |
91 | 86 | * 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> |
97 | 87 | * </ul> |
98 | 88 | * |
| 89 | + * <h3>Warning</h3> |
99 | 90 | * <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. |
103 | 102 | * </p> |
104 | 103 | * |
105 | 104 | * @since 5.6 |
106 | 105 | */ |
107 | | - |
108 | 106 | @Contract(threading = ThreadingBehavior.STATELESS) |
109 | 107 | public final class EnvironmentProxyConfigurer { |
110 | 108 |
|
|
0 commit comments