equal
deleted
inserted
replaced
173 * and returns the same instance. Builders are not thread-safe and should not be |
173 * and returns the same instance. Builders are not thread-safe and should not be |
174 * used concurrently from multiple threads without external synchronization. |
174 * used concurrently from multiple threads without external synchronization. |
175 * |
175 * |
176 * @since 11 |
176 * @since 11 |
177 */ |
177 */ |
178 public abstract static class Builder { |
178 public interface Builder { |
179 |
179 |
180 /** |
180 /** |
181 * A proxy selector that always return {@link Proxy#NO_PROXY} implying |
181 * A proxy selector that always return {@link Proxy#NO_PROXY} implying |
182 * a direct connection. |
182 * a direct connection. |
183 * |
183 * |
185 * {@link #proxy(ProxySelector)} in order to build an instance of |
185 * {@link #proxy(ProxySelector)} in order to build an instance of |
186 * {@link HttpClient} that uses no proxy. |
186 * {@link HttpClient} that uses no proxy. |
187 */ |
187 */ |
188 public static final ProxySelector NO_PROXY = ProxySelector.of(null); |
188 public static final ProxySelector NO_PROXY = ProxySelector.of(null); |
189 |
189 |
190 /** |
|
191 * Creates a Builder. |
|
192 */ |
|
193 protected Builder() {} |
|
194 |
190 |
195 /** |
191 /** |
196 * Sets a cookie handler. |
192 * Sets a cookie handler. |
197 * |
193 * |
198 * @param cookieHandler the cookie handler |
194 * @param cookieHandler the cookie handler |
199 * @return this builder |
195 * @return this builder |
200 */ |
196 */ |
201 public abstract Builder cookieHandler(CookieHandler cookieHandler); |
197 public Builder cookieHandler(CookieHandler cookieHandler); |
202 |
198 |
203 /** |
199 /** |
204 * Sets an {@code SSLContext}. |
200 * Sets an {@code SSLContext}. |
205 * |
201 * |
206 * <p> If this method is not invoked prior to {@linkplain #build() |
202 * <p> If this method is not invoked prior to {@linkplain #build() |
210 * require client authentication. |
206 * require client authentication. |
211 * |
207 * |
212 * @param sslContext the SSLContext |
208 * @param sslContext the SSLContext |
213 * @return this builder |
209 * @return this builder |
214 */ |
210 */ |
215 public abstract Builder sslContext(SSLContext sslContext); |
211 public Builder sslContext(SSLContext sslContext); |
216 |
212 |
217 /** |
213 /** |
218 * Sets an {@code SSLParameters}. |
214 * Sets an {@code SSLParameters}. |
219 * |
215 * |
220 * <p> If this method is not invoked prior to {@linkplain #build() |
216 * <p> If this method is not invoked prior to {@linkplain #build() |
227 * object are copied. |
223 * object are copied. |
228 * |
224 * |
229 * @param sslParameters the SSLParameters |
225 * @param sslParameters the SSLParameters |
230 * @return this builder |
226 * @return this builder |
231 */ |
227 */ |
232 public abstract Builder sslParameters(SSLParameters sslParameters); |
228 public Builder sslParameters(SSLParameters sslParameters); |
233 |
229 |
234 /** |
230 /** |
235 * Sets the executor to be used for asynchronous and dependent tasks. |
231 * Sets the executor to be used for asynchronous and dependent tasks. |
236 * |
232 * |
237 * <p> If this method is not invoked prior to {@linkplain #build() |
233 * <p> If this method is not invoked prior to {@linkplain #build() |
245 * has no permissions. |
241 * has no permissions. |
246 * |
242 * |
247 * @param executor the Executor |
243 * @param executor the Executor |
248 * @return this builder |
244 * @return this builder |
249 */ |
245 */ |
250 public abstract Builder executor(Executor executor); |
246 public Builder executor(Executor executor); |
251 |
247 |
252 /** |
248 /** |
253 * Specifies whether requests will automatically follow redirects issued |
249 * Specifies whether requests will automatically follow redirects issued |
254 * by the server. |
250 * by the server. |
255 * |
251 * |
258 * policy of {@link Redirect#NEVER NEVER}. |
254 * policy of {@link Redirect#NEVER NEVER}. |
259 * |
255 * |
260 * @param policy the redirection policy |
256 * @param policy the redirection policy |
261 * @return this builder |
257 * @return this builder |
262 */ |
258 */ |
263 public abstract Builder followRedirects(Redirect policy); |
259 public Builder followRedirects(Redirect policy); |
264 |
260 |
265 /** |
261 /** |
266 * Requests a specific HTTP protocol version where possible. |
262 * Requests a specific HTTP protocol version where possible. |
267 * |
263 * |
268 * <p> If this method is not invoked prior to {@linkplain #build() |
264 * <p> If this method is not invoked prior to {@linkplain #build() |
282 * does not support this mode, then HTTP/1.1 may be used |
278 * does not support this mode, then HTTP/1.1 may be used |
283 * |
279 * |
284 * @param version the requested HTTP protocol version |
280 * @param version the requested HTTP protocol version |
285 * @return this builder |
281 * @return this builder |
286 */ |
282 */ |
287 public abstract Builder version(HttpClient.Version version); |
283 public Builder version(HttpClient.Version version); |
288 |
284 |
289 /** |
285 /** |
290 * Sets the default priority for any HTTP/2 requests sent from this |
286 * Sets the default priority for any HTTP/2 requests sent from this |
291 * client. The value provided must be between {@code 1} and {@code 256} |
287 * client. The value provided must be between {@code 1} and {@code 256} |
292 * (inclusive). |
288 * (inclusive). |
293 * |
289 * |
294 * @param priority the priority weighting |
290 * @param priority the priority weighting |
295 * @return this builder |
291 * @return this builder |
296 * @throws IllegalArgumentException if the given priority is out of range |
292 * @throws IllegalArgumentException if the given priority is out of range |
297 */ |
293 */ |
298 public abstract Builder priority(int priority); |
294 public Builder priority(int priority); |
299 |
295 |
300 /** |
296 /** |
301 * Sets a {@link java.net.ProxySelector}. |
297 * Sets a {@link java.net.ProxySelector}. |
302 * |
298 * |
303 * @apiNote {@link ProxySelector#of(InetSocketAddress) ProxySelector::of} |
299 * @apiNote {@link ProxySelector#of(InetSocketAddress) ProxySelector::of} |
316 * {@linkplain #build() building}. |
312 * {@linkplain #build() building}. |
317 * |
313 * |
318 * @param selector the ProxySelector |
314 * @param selector the ProxySelector |
319 * @return this builder |
315 * @return this builder |
320 */ |
316 */ |
321 public abstract Builder proxy(ProxySelector selector); |
317 public Builder proxy(ProxySelector selector); |
322 |
318 |
323 /** |
319 /** |
324 * Sets an authenticator to use for HTTP authentication. |
320 * Sets an authenticator to use for HTTP authentication. |
325 * |
321 * |
326 * @param a the Authenticator |
322 * @param a the Authenticator |
327 * @return this builder |
323 * @return this builder |
328 */ |
324 */ |
329 public abstract Builder authenticator(Authenticator a); |
325 public Builder authenticator(Authenticator a); |
330 |
326 |
331 /** |
327 /** |
332 * Returns a new {@link HttpClient} built from the current state of this |
328 * Returns a new {@link HttpClient} built from the current state of this |
333 * builder. |
329 * builder. |
334 * |
330 * |
335 * @return this builder |
331 * @return this builder |
336 */ |
332 */ |
337 public abstract HttpClient build(); |
333 public HttpClient build(); |
338 } |
334 } |
339 |
335 |
340 |
336 |
341 /** |
337 /** |
342 * Returns an {@code Optional} containing this client's {@link |
338 * Returns an {@code Optional} containing this client's {@link |