src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpClient.java
branchhttp-client-branch
changeset 55821 fa0fc03c0853
parent 55816 70738768515a
child 55822 28dcbbc4148b
equal deleted inserted replaced
55820:76d033c9908f 55821:fa0fc03c0853
    27 
    27 
    28 import java.io.IOException;
    28 import java.io.IOException;
    29 import java.net.Authenticator;
    29 import java.net.Authenticator;
    30 import java.net.CookieHandler;
    30 import java.net.CookieHandler;
    31 import java.net.InetSocketAddress;
    31 import java.net.InetSocketAddress;
       
    32 import java.net.Proxy;
    32 import java.net.ProxySelector;
    33 import java.net.ProxySelector;
    33 import java.net.URI;
    34 import java.net.URI;
    34 import java.util.Optional;
    35 import java.util.Optional;
    35 import java.util.concurrent.CompletableFuture;
    36 import java.util.concurrent.CompletableFuture;
    36 import java.util.concurrent.Executor;
    37 import java.util.concurrent.Executor;
    64      *
    65      *
    65      * Equivalent to {@code newBuilder().build()}.
    66      * Equivalent to {@code newBuilder().build()}.
    66      *
    67      *
    67      * The default settings include: the "GET" request method, a preference of
    68      * The default settings include: the "GET" request method, a preference of
    68      * {@linkplain HttpClient.Version#HTTP_2 HTTP/2}, a redirection policy of
    69      * {@linkplain HttpClient.Version#HTTP_2 HTTP/2}, a redirection policy of
    69      * {@linkplain Redirect#NEVER NEVER}, and the {@linkplain
    70      * {@linkplain Redirect#NEVER NEVER}, the {@linkplain
       
    71      * ProxySelector#getDefault() default proxy selector}, and the {@linkplain
    70      * SSLContext#getDefault() default SSL context}.
    72      * SSLContext#getDefault() default SSL context}.
       
    73      *
       
    74      * @implNote The system-wide default values are retrieved at the time the
       
    75      * {@code HttpClient} instance is constructed. Changing the system-wide
       
    76      * values after an {@code HttpClient} instance has been built, for
       
    77      * instance, by calling {@link ProxySelector#setDefault(ProxySelector)},
       
    78      * has no effect on already built instances.
    71      *
    79      *
    72      * @return a new HttpClient
    80      * @return a new HttpClient
    73      */
    81      */
    74     public static HttpClient newHttpClient() {
    82     public static HttpClient newHttpClient() {
    75         return newBuilder().build();
    83         return newBuilder().build();
    94      * used concurrently from multiple threads without external synchronization.
   102      * used concurrently from multiple threads without external synchronization.
    95      *
   103      *
    96      * @since 9
   104      * @since 9
    97      */
   105      */
    98     public abstract static class Builder {
   106     public abstract static class Builder {
       
   107 
       
   108         /**
       
   109          * A proxy selector that always return {@link Proxy#NO_PROXY} implying
       
   110          * a direct connection.
       
   111          * This is a convenience object that can be passed to {@link #proxy(ProxySelector)}
       
   112          * in order to build an instance of {@link HttpClient} that uses no
       
   113          * proxy.
       
   114          */
       
   115         public static final ProxySelector NO_PROXY = ProxySelector.of(null);
    99 
   116 
   100         /**
   117         /**
   101          * Creates a Builder.
   118          * Creates a Builder.
   102          */
   119          */
   103         protected Builder() {}
   120         protected Builder() {}
   207         public abstract Builder priority(int priority);
   224         public abstract Builder priority(int priority);
   208 
   225 
   209         /**
   226         /**
   210          * Sets a {@link java.net.ProxySelector}.
   227          * Sets a {@link java.net.ProxySelector}.
   211          *
   228          *
   212          * @implNote {@link ProxySelector#of(InetSocketAddress)}
   229          * @apiNote {@link ProxySelector#of(InetSocketAddress)}
   213          * provides a {@code ProxySelector} which uses a single proxy for all
   230          * provides a {@code ProxySelector} which uses a single proxy for all
   214          * requests. The system-wide proxy selector can be retrieved by
   231          * requests. The system-wide proxy selector can be retrieved by
   215          * {@link ProxySelector#getDefault()}.
   232          * {@link ProxySelector#getDefault()}.
   216          *
   233          *
       
   234          * @implNote
       
   235          * If this method is not invoked prior to {@linkplain #build()
       
   236          * building}, then newly built clients will use the {@linkplain
       
   237          * ProxySelector#getDefault() default proxy selector}, which
       
   238          * is normally adequate for client applications. This default
       
   239          * behavior can be turned off by supplying an explicit proxy
       
   240          * selector to this method, such as {@link #NO_PROXY} or one
       
   241          * returned by {@link ProxySelector#of(InetSocketAddress)},
       
   242          * before calling {@link #build()}.
       
   243          *
   217          * @param selector the ProxySelector
   244          * @param selector the ProxySelector
   218          * @return this builder
   245          * @return this builder
   219          */
   246          */
   220         public abstract Builder proxy(ProxySelector selector);
   247         public abstract Builder proxy(ProxySelector selector);
   221 
   248 
   254      * @return this client's follow redirects setting
   281      * @return this client's follow redirects setting
   255      */
   282      */
   256     public abstract Redirect followRedirects();
   283     public abstract Redirect followRedirects();
   257 
   284 
   258     /**
   285     /**
   259      * Returns an {@code Optional} containing this client's {@code ProxySelector}.
   286      * Returns an {@code Optional} containing the {@code ProxySelector}
   260      * If no proxy selector was set in this client's builder, then the {@code
   287      * supplied to this client. If no proxy selector was set in this client's
   261      * Optional} is empty.
   288      * builder, then the {@code Optional} is empty.
   262      *
   289      *
   263      * @return an {@code Optional} containing this client's proxy selector
   290      * <p> Even though this method may return an empty optional, the {@code
       
   291      * HttpClient} may still have an non-exposed {@linkplain
       
   292      * Builder#proxy(ProxySelector) default proxy selector} that is
       
   293      * used for sending HTTP requests.
       
   294      *
       
   295      * @return an {@code Optional} containing the proxy selector supplied
       
   296      *        to this client.
   264      */
   297      */
   265     public abstract Optional<ProxySelector> proxy();
   298     public abstract Optional<ProxySelector> proxy();
   266 
   299 
   267     /**
   300     /**
   268      * Returns this client's {@code SSLContext}.
   301      * Returns this client's {@code SSLContext}.