src/java.net.http/share/classes/java/net/http/HttpClient.java
author chegar
Wed, 07 Feb 2018 21:45:37 +0000
branchhttp-client-branch
changeset 56092 fd85b2bf2b0d
parent 56089 42208b2f224e
child 56097 15dc43936d39
permissions -rw-r--r--
http-client-branch: move implementation to jdk.internal.net.http
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
     1
/*
56079
d23b02f37fce http-client-branch: more remaining impl types to internal
chegar
parents: 56043
diff changeset
     2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
     4
 *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    10
 *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    15
 * accompanied this code).
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    16
 *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    20
 *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    23
 * questions.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    24
 */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    25
56089
42208b2f224e http-client-branch: move to standard package and module name
chegar
parents: 56087
diff changeset
    26
package java.net.http;
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    27
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    28
import java.io.IOException;
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    29
import java.net.Authenticator;
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
    30
import java.net.CookieHandler;
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    31
import java.net.InetSocketAddress;
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
    32
import java.net.Proxy;
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    33
import java.net.ProxySelector;
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    34
import java.util.Optional;
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    35
import java.util.concurrent.CompletableFuture;
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    36
import java.util.concurrent.Executor;
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
    37
import java.util.concurrent.Executors;
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
    38
import java.util.concurrent.ThreadFactory;
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    39
import javax.net.ssl.SSLContext;
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    40
import javax.net.ssl.SSLParameters;
56089
42208b2f224e http-client-branch: move to standard package and module name
chegar
parents: 56087
diff changeset
    41
import java.net.http.HttpResponse.BodyHandler;
42208b2f224e http-client-branch: move to standard package and module name
chegar
parents: 56087
diff changeset
    42
import java.net.http.HttpResponse.PushPromiseHandler;
56092
fd85b2bf2b0d http-client-branch: move implementation to jdk.internal.net.http
chegar
parents: 56089
diff changeset
    43
import jdk.internal.net.http.HttpClientBuilderImpl;
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    44
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    45
/**
56085
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    46
 * An HTTP Client.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    47
 *
56085
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    48
 * <p> An {@code HttpClient} can be used to send requests and retrieve their
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    49
 * responses. An {@code HttpClient} is created through a {@link
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    50
 * HttpClient#newBuilder() builder}. The builder can be used to configure
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    51
 * per-client state, like: the preferred protocol version ( HTTP/1.1 or HTTP/2 ),
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    52
 * whether to follow redirects, a proxy, an authenticator, etc. Once built, an
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    53
 * {@code HttpClient} is immutable, and can be used to send multiple requests.
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    54
 *
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    55
 * <p> An {@code HttpClient} provides configuration information, and resource
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    56
 * sharing, for all requests send through it.
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    57
 *
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    58
 * <p>For Example:
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    59
 * <pre>{@code    HttpClient client = HttpClient.newBuilder()
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    60
 *        .version(Version.HTTP_2)
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    61
 *        .followRedirects(Redirect.SAME_PROTOCOL)
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    62
 *        .proxy(ProxySelector.of(new InetSocketAddress("proxy.com", 8080)))
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    63
 *        .authenticator(Authenticator.getDefault())
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    64
 *        .build();
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    65
 *
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    66
 *   HttpRequest request = HttpRequest.newBuilder()
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    67
 *        .uri(URI.create("http://foo.com/"))
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    68
 *        .timeout(Duration.ofMinutes(1))
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    69
 *        .header("Content-Type", "application/json")
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    70
 *        .POST(BodyPublisher.fromFile(Paths.get("file.json")))
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    71
 *        .build();
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    72
 *
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    73
 *   client.sendAsync(request, BodyHandler.asString())
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    74
 *        .thenApply(HttpResponse::body)
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    75
 *        .thenAccept(System.out::println)
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    76
 *        .join();  }</pre>
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    77
 *
544869ae0b16 http-client-branch: remove remaining vestiges of MultiSubscriber and minor doc cleanup
chegar
parents: 56079
diff changeset
    78
 * <p> See {@link HttpRequest} for further examples of usage of this API.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    79
 *
56086
ba42a59d3072 http-client-branch: update public API @since tags
chegar
parents: 56085
diff changeset
    80
 * @since 11
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    81
 */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    82
public abstract class HttpClient {
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    83
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    84
    /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    85
     * Creates an HttpClient.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    86
     */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    87
    protected HttpClient() {}
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    88
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    89
    /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    90
     * Returns a new HttpClient with default settings.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
    91
     *
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
    92
     * <p> Equivalent to {@code newBuilder().build()}.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
    93
     *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
    94
     * <p> The default settings include: the "GET" request method, a preference
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
    95
     * of {@linkplain HttpClient.Version#HTTP_2 HTTP/2}, a redirection policy of
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
    96
     * {@linkplain Redirect#NEVER NEVER}, the {@linkplain
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
    97
     * ProxySelector#getDefault() default proxy selector}, and the {@linkplain
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
    98
     * SSLContext#getDefault() default SSL context}.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
    99
     *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   100
     * @implNote The system-wide default values are retrieved at the time the
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   101
     * {@code HttpClient} instance is constructed. Changing the system-wide
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   102
     * values after an {@code HttpClient} instance has been built, for
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   103
     * instance, by calling {@link ProxySelector#setDefault(ProxySelector)}
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   104
     * or {@link SSLContext#setDefault(SSLContext)}, has no effect on already
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   105
     * built instances.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   106
     *
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   107
     * @return a new HttpClient
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   108
     */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   109
    public static HttpClient newHttpClient() {
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   110
        return newBuilder().build();
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   111
    }
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   112
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   113
    /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   114
     * Creates a new {@code HttpClient} builder.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   115
     *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   116
     * @return a {@code HttpClient.Builder}
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   117
     */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   118
    public static Builder newBuilder() {
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   119
        return new HttpClientBuilderImpl();
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   120
    }
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   121
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   122
    /**
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   123
     * A builder of immutable {@link HttpClient}s.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   124
     *
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   125
     * <p> Builders are created by invoking {@linkplain HttpClient#newBuilder()
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   126
     * newBuilder}. Each of the setter methods modifies the state of the builder
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   127
     * and returns the same instance. Builders are not thread-safe and should not be
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   128
     * used concurrently from multiple threads without external synchronization.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   129
     *
56086
ba42a59d3072 http-client-branch: update public API @since tags
chegar
parents: 56085
diff changeset
   130
     * @since 11
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   131
     */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   132
    public abstract static class Builder {
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   133
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   134
        /**
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   135
         * A proxy selector that always return {@link Proxy#NO_PROXY} implying
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   136
         * a direct connection.
56079
d23b02f37fce http-client-branch: more remaining impl types to internal
chegar
parents: 56043
diff changeset
   137
         *
d23b02f37fce http-client-branch: more remaining impl types to internal
chegar
parents: 56043
diff changeset
   138
         * <p> This is a convenience object that can be passed to
d23b02f37fce http-client-branch: more remaining impl types to internal
chegar
parents: 56043
diff changeset
   139
         * {@link #proxy(ProxySelector)} in order to build an instance of
d23b02f37fce http-client-branch: more remaining impl types to internal
chegar
parents: 56043
diff changeset
   140
         * {@link HttpClient} that uses no proxy.
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   141
         */
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   142
        public static final ProxySelector NO_PROXY = ProxySelector.of(null);
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   143
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   144
        /**
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   145
         * Creates a Builder.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   146
         */
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   147
        protected Builder() {}
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   148
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   149
        /**
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   150
         * Sets a cookie handler.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   151
         *
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   152
         * @param cookieHandler the cookie handler
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   153
         * @return this builder
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   154
         */
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   155
        public abstract Builder cookieHandler(CookieHandler cookieHandler);
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   156
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   157
        /**
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   158
         * Sets an {@code SSLContext}.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   159
         *
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   160
         * <p> If this method is not invoked prior to {@linkplain #build()
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   161
         * building}, then newly built clients will use the {@linkplain
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   162
         * SSLContext#getDefault() default context}, which is normally adequate
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   163
         * for client applications that do not need to specify protocols, or
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   164
         * require client authentication.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   165
         *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   166
         * @param sslContext the SSLContext
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   167
         * @return this builder
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   168
         */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   169
        public abstract Builder sslContext(SSLContext sslContext);
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   170
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   171
        /**
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   172
         * Sets an {@code SSLParameters}.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   173
         *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   174
         * <p> If this method is not invoked prior to {@linkplain #build()
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   175
         * building}, then newly built clients will use a default,
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   176
         * implementation specific, set of parameters.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   177
         *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   178
         * <p> Some parameters which are used internally by the HTTP Client
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   179
         * implementation (such as the application protocol list) should not be
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   180
         * set by callers, as they may be ignored. The contents of the given
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   181
         * object are copied.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   182
         *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   183
         * @param sslParameters the SSLParameters
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   184
         * @return this builder
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   185
         */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   186
        public abstract Builder sslParameters(SSLParameters sslParameters);
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   187
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   188
        /**
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   189
         * Sets the executor to be used for asynchronous and dependent tasks.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   190
         *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   191
         * <p> If this method is not invoked prior to {@linkplain #build()
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   192
         * building}, a default executor is created for each newly built {@code
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   193
         * HttpClient}. The default executor uses a {@linkplain
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   194
         * Executors#newCachedThreadPool(ThreadFactory) cached thread pool},
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   195
         * with a custom thread factory.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   196
         *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   197
         * @implNote If a security manager has been installed, the thread
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   198
         * factory creates threads that run with an access control context that
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   199
         * has no permissions.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   200
         *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   201
         * @param executor the Executor
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   202
         * @return this builder
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   203
         */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   204
        public abstract Builder executor(Executor executor);
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   205
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   206
        /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   207
         * Specifies whether requests will automatically follow redirects issued
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   208
         * by the server.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   209
         *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   210
         * <p> If this method is not invoked prior to {@linkplain #build()
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   211
         * building}, then newly built clients will use a default redirection
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   212
         * policy of {@link Redirect#NEVER NEVER}.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   213
         *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   214
         * @param policy the redirection policy
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   215
         * @return this builder
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   216
         */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   217
        public abstract Builder followRedirects(Redirect policy);
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   218
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   219
        /**
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   220
         * Requests a specific HTTP protocol version where possible.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   221
         *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   222
         * <p> If this method is not invoked prior to {@linkplain #build()
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   223
         * building}, then newly built clients will prefer {@linkplain
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   224
         * Version#HTTP_2 HTTP/2}.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   225
         *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   226
         * <p> If set to {@linkplain Version#HTTP_2 HTTP/2}, then each request
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   227
         * will attempt to upgrade to HTTP/2. If the upgrade succeeds, then the
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   228
         * response to this request will use HTTP/2 and all subsequent requests
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   229
         * and responses to the same
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   230
         * <a href="https://tools.ietf.org/html/rfc6454#section-4">origin server</a>
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   231
         * will use HTTP/2. If the upgrade fails, then the response will be
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   232
         * handled using HTTP/1.1
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   233
         *
56079
d23b02f37fce http-client-branch: more remaining impl types to internal
chegar
parents: 56043
diff changeset
   234
         * @implNote Constraints may also affect the selection of protocol version.
56043
08e8e41841cf http-client-branch: changed default protocol version when plain http over proxy requested.
michaelm
parents: 56025
diff changeset
   235
         * For example, if HTTP/2 is requested through a proxy, and if the implementation
08e8e41841cf http-client-branch: changed default protocol version when plain http over proxy requested.
michaelm
parents: 56025
diff changeset
   236
         * does not support this mode, then HTTP/1.1 may be used
08e8e41841cf http-client-branch: changed default protocol version when plain http over proxy requested.
michaelm
parents: 56025
diff changeset
   237
         *
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   238
         * @param version the requested HTTP protocol version
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   239
         * @return this builder
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   240
         */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   241
        public abstract Builder version(HttpClient.Version version);
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   242
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   243
        /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   244
         * Sets the default priority for any HTTP/2 requests sent from this
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   245
         * client. The value provided must be between {@code 1} and {@code 256}
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   246
         * (inclusive).
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   247
         *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   248
         * @param priority the priority weighting
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   249
         * @return this builder
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   250
         * @throws IllegalArgumentException if the given priority is out of range
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   251
         */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   252
        public abstract Builder priority(int priority);
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   253
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   254
        /**
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   255
         * Sets a {@link java.net.ProxySelector}.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   256
         *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   257
         * @apiNote {@link ProxySelector#of(InetSocketAddress)}
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   258
         * provides a {@code ProxySelector} which uses a single proxy for all
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   259
         * requests. The system-wide proxy selector can be retrieved by
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   260
         * {@link ProxySelector#getDefault()}.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   261
         *
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   262
         * @implNote
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   263
         * If this method is not invoked prior to {@linkplain #build()
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   264
         * building}, then newly built clients will use the {@linkplain
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   265
         * ProxySelector#getDefault() default proxy selector}, which
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   266
         * is normally adequate for client applications. This default
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   267
         * behavior can be turned off by supplying an explicit proxy
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   268
         * selector to this method, such as {@link #NO_PROXY} or one
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   269
         * returned by {@link ProxySelector#of(InetSocketAddress)},
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   270
         * before calling {@link #build()}.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   271
         *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   272
         * @param selector the ProxySelector
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   273
         * @return this builder
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   274
         */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   275
        public abstract Builder proxy(ProxySelector selector);
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   276
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   277
        /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   278
         * Sets an authenticator to use for HTTP authentication.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   279
         *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   280
         * @param a the Authenticator
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   281
         * @return this builder
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   282
         */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   283
        public abstract Builder authenticator(Authenticator a);
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   284
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   285
        /**
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   286
         * Returns a new {@link HttpClient} built from the current state of this
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   287
         * builder.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   288
         *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   289
         * @return this builder
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   290
         */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   291
        public abstract HttpClient build();
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   292
    }
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   293
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   294
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   295
    /**
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   296
     * Returns an {@code Optional} containing this client's {@linkplain
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   297
     * CookieHandler}. If no {@code CookieHandler} was set in this client's
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   298
     * builder, then the {@code Optional} is empty.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   299
     *
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   300
     * @return an {@code Optional} containing this client's {@code CookieHandler}
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   301
     */
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   302
    public abstract Optional<CookieHandler> cookieHandler();
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   303
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   304
    /**
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   305
     * Returns the follow redirects policy for this client. The default value
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   306
     * for client's built by builders that do not specify a redirect policy is
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   307
     * {@link HttpClient.Redirect#NEVER NEVER}.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   308
     *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   309
     * @return this client's follow redirects setting
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   310
     */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   311
    public abstract Redirect followRedirects();
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   312
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   313
    /**
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   314
     * Returns an {@code Optional} containing the {@code ProxySelector}
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   315
     * supplied to this client. If no proxy selector was set in this client's
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   316
     * builder, then the {@code Optional} is empty.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   317
     *
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   318
     * <p> Even though this method may return an empty optional, the {@code
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   319
     * HttpClient} may still have an non-exposed {@linkplain
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   320
     * Builder#proxy(ProxySelector) default proxy selector} that is
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   321
     * used for sending HTTP requests.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   322
     *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   323
     * @return an {@code Optional} containing the proxy selector supplied
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   324
     *        to this client.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   325
     */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   326
    public abstract Optional<ProxySelector> proxy();
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   327
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   328
    /**
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   329
     * Returns this client's {@code SSLContext}.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   330
     *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   331
     * <p> If no {@code SSLContext} was set in this client's builder, then the
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   332
     * {@linkplain SSLContext#getDefault() default context} is returned.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   333
     *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   334
     * @return this client's SSLContext
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   335
     */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   336
    public abstract SSLContext sslContext();
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   337
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   338
    /**
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   339
     * Returns a copy of this client's {@link SSLParameters}.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   340
     *
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   341
     * <p> If no {@code SSLParameters} were set in the client's builder, then an
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   342
     * implementation specific default set of parameters, that the client will
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   343
     * use, is returned.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   344
     *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   345
     * @return this client's {@code SSLParameters}
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   346
     */
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   347
    public abstract SSLParameters sslParameters();
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   348
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   349
    /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   350
     * Returns an {@code Optional} containing the {@link Authenticator} set on
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   351
     * this client. If no {@code Authenticator} was set in the client's builder,
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   352
     * then the {@code Optional} is empty.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   353
     *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   354
     * @return an {@code Optional} containing this client's {@code Authenticator}
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   355
     */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   356
    public abstract Optional<Authenticator> authenticator();
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   357
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   358
    /**
56043
08e8e41841cf http-client-branch: changed default protocol version when plain http over proxy requested.
michaelm
parents: 56025
diff changeset
   359
     * Returns the preferred HTTP protocol version for this client. The default
44854
5a486e0acd29 8175814: Update default HttpClient protocol version and optional request version
michaelm
parents: 43302
diff changeset
   360
     * value is {@link HttpClient.Version#HTTP_2}
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   361
     *
56079
d23b02f37fce http-client-branch: more remaining impl types to internal
chegar
parents: 56043
diff changeset
   362
     * @implNote Constraints may also affect the selection of protocol version.
d23b02f37fce http-client-branch: more remaining impl types to internal
chegar
parents: 56043
diff changeset
   363
     * For example, if HTTP/2 is requested through a proxy, and if the
d23b02f37fce http-client-branch: more remaining impl types to internal
chegar
parents: 56043
diff changeset
   364
     * implementation does not support this mode, then HTTP/1.1 may be used
56043
08e8e41841cf http-client-branch: changed default protocol version when plain http over proxy requested.
michaelm
parents: 56025
diff changeset
   365
     *
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   366
     * @return the HTTP protocol version requested
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   367
     */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   368
    public abstract HttpClient.Version version();
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   369
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   370
    /**
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   371
     * Returns an {@code Optional} containing this client's {@linkplain
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   372
     * Executor}. If no {@code Executor} was set in the client's builder,
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   373
     * then the {@code Optional} is empty.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   374
     *
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   375
     * <p> Even though this method may return an empty optional, the {@code
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   376
     * HttpClient} may still have an non-exposed {@linkplain
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   377
     * HttpClient.Builder#executor(Executor) default executor} that is used for
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   378
     * executing asynchronous and dependent tasks.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   379
     *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   380
     * @return an {@code Optional} containing this client's {@code Executor}
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   381
     */
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   382
    public abstract Optional<Executor> executor();
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   383
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   384
    /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   385
     * The HTTP protocol version.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   386
     *
56086
ba42a59d3072 http-client-branch: update public API @since tags
chegar
parents: 56085
diff changeset
   387
     * @since 11
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   388
     */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   389
    public enum Version {
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   390
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   391
        /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   392
         * HTTP version 1.1
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   393
         */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   394
        HTTP_1_1,
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   395
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   396
        /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   397
         * HTTP version 2
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   398
         */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   399
        HTTP_2
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   400
    }
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   401
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   402
    /**
43302
45de1dc92ecd 8173354: javadoc warning notice for types in Incubator Modules
chegar
parents: 42460
diff changeset
   403
     * Defines automatic redirection policy.
45de1dc92ecd 8173354: javadoc warning notice for types in Incubator Modules
chegar
parents: 42460
diff changeset
   404
     *
45de1dc92ecd 8173354: javadoc warning notice for types in Incubator Modules
chegar
parents: 42460
diff changeset
   405
     * <p> This is checked whenever a {@code 3XX} response code is received. If
45de1dc92ecd 8173354: javadoc warning notice for types in Incubator Modules
chegar
parents: 42460
diff changeset
   406
     * redirection does not happen automatically then the response is returned
45de1dc92ecd 8173354: javadoc warning notice for types in Incubator Modules
chegar
parents: 42460
diff changeset
   407
     * to the user, where it can be handled manually.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   408
     *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   409
     * <p> {@code Redirect} policy is set via the {@link
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   410
     * HttpClient.Builder#followRedirects(HttpClient.Redirect)} method.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   411
     *
56086
ba42a59d3072 http-client-branch: update public API @since tags
chegar
parents: 56085
diff changeset
   412
     * @since 11
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   413
     */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   414
    public enum Redirect {
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   415
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   416
        /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   417
         * Never redirect.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   418
         */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   419
        NEVER,
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   420
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   421
        /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   422
         * Always redirect.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   423
         */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   424
        ALWAYS,
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   425
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   426
        /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   427
         * Redirect to same protocol only. Redirection may occur from HTTP URLs
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   428
         * to other HTTP URLs, and from HTTPS URLs to other HTTPS URLs.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   429
         */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   430
        SAME_PROTOCOL,
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   431
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   432
        /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   433
         * Redirect always except from HTTPS URLs to HTTP URLs.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   434
         */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   435
        SECURE
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   436
    }
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   437
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   438
    /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   439
     * Sends the given request using this client, blocking if necessary to get
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   440
     * the response. The returned {@link HttpResponse}{@code <T>} contains the
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   441
     * response status, headers, and body ( as handled by given response body
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   442
     * handler ).
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   443
     *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   444
     * @param <T> the response body type
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   445
     * @param req the request
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   446
     * @param responseBodyHandler the response body handler
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   447
     * @return the response body
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   448
     * @throws IOException if an I/O error occurs when sending or receiving
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   449
     * @throws InterruptedException if the operation is interrupted
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   450
     * @throws IllegalArgumentException if the request method is not supported
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   451
     * @throws SecurityException If a security manager has been installed
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   452
     *          and it denies {@link java.net.URLPermission access} to the
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   453
     *          URL in the given request, or proxy if one is configured.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   454
     *          See HttpRequest for further information about
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   455
     *          <a href="HttpRequest.html#securitychecks">security checks</a>.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   456
     */
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   457
    public abstract <T> HttpResponse<T>
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   458
    send(HttpRequest req, HttpResponse.BodyHandler<T> responseBodyHandler)
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   459
        throws IOException, InterruptedException;
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   461
    /**
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   462
     * Sends the given request asynchronously using this client and the given
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   463
     * response handler.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   464
     *
56025
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   465
     * <p> Equivalent to {@code sendAsync(request, responseBodyHandler, null)}.
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   466
     *
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   467
     * @param <T> the response body type
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   468
     * @param request the request
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   469
     * @param responseBodyHandler the response body handler
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   470
     * @return a {@code CompletableFuture<HttpResponse<T>>}
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   471
     */
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   472
    public abstract <T> CompletableFuture<HttpResponse<T>>
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   473
    sendAsync(HttpRequest request,
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   474
              BodyHandler<T> responseBodyHandler);
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   475
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   476
    /**
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   477
     * Sends the given request asynchronously using this client with the given
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   478
     * response body handler and push promise handler.
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   479
     *
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   480
     * <p> The returned completable future, if completed successfully, completes
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   481
     * with an {@link HttpResponse}{@code <T>} that contains the response status,
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   482
     * headers, and body ( as handled by given response body handler ).
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   483
     *
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   484
     * <p> {@linkplain PushPromiseHandler Push promises} received, if any, are
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   485
     * handled by the given {@code pushPromiseHandler}. A {@code null} valued
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   486
     * {@code pushPromiseHandler} rejects any push promises.
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   487
     *
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   488
     * <p> The returned completable future completes exceptionally with:
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   489
     * <ul>
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   490
     * <li>{@link IOException} - if an I/O error occurs when sending or receiving</li>
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   491
     * <li>{@link IllegalArgumentException} - if the request method is not supported</li>
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   492
     * <li>{@link SecurityException} - If a security manager has been installed
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   493
     *          and it denies {@link java.net.URLPermission access} to the
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   494
     *          URL in the given request, or proxy if one is configured.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   495
     *          See HttpRequest for further information about
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   496
     *          <a href="HttpRequest.html#securitychecks">security checks</a>.</li>
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   497
     * </ul>
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   498
     *
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   499
     * @param <T> the response body type
56025
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   500
     * @param request the request
56010
782b2f2d1e76 http-client-branch: updated server push API
michaelm
parents: 55973
diff changeset
   501
     * @param responseBodyHandler the response body handler
782b2f2d1e76 http-client-branch: updated server push API
michaelm
parents: 55973
diff changeset
   502
     * @param pushPromiseHandler push promise handler, may be null
782b2f2d1e76 http-client-branch: updated server push API
michaelm
parents: 55973
diff changeset
   503
     * @return a {@code CompletableFuture<HttpResponse<T>>}
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   504
     */
56010
782b2f2d1e76 http-client-branch: updated server push API
michaelm
parents: 55973
diff changeset
   505
    public abstract <T> CompletableFuture<HttpResponse<T>>
56025
1f88e1587067 http-cient-branch: cleanup push promise spec
chegar
parents: 56010
diff changeset
   506
    sendAsync(HttpRequest request,
56010
782b2f2d1e76 http-client-branch: updated server push API
michaelm
parents: 55973
diff changeset
   507
              BodyHandler<T> responseBodyHandler,
782b2f2d1e76 http-client-branch: updated server push API
michaelm
parents: 55973
diff changeset
   508
              PushPromiseHandler<T> pushPromiseHandler);
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   509
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   510
    /**
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   511
     * Creates a new {@code WebSocket} builder (optional operation).
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   512
     *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   513
     * <p> <b>Example</b>
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   514
     * <pre>{@code
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   515
     *     HttpClient client = HttpClient.newHttpClient();
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   516
     *     CompletableFuture<WebSocket> ws = client.newWebSocketBuilder()
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   517
     *             .buildAsync(URI.create("ws://websocket.example.com"), listener);
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   518
     * }</pre>
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   519
     *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   520
     * <p> Finer control over the WebSocket Opening Handshake can be achieved
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   521
     * by using a custom {@code HttpClient}.
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   522
     *
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   523
     * <p> <b>Example</b>
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   524
     * <pre>{@code
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   525
     *     InetSocketAddress addr = new InetSocketAddress("proxy.example.com", 80);
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   526
     *     HttpClient client = HttpClient.newBuilder()
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   527
     *             .proxy(ProxySelector.of(addr))
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   528
     *             .build();
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   529
     *     CompletableFuture<WebSocket> ws = client.newWebSocketBuilder()
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   530
     *             .buildAsync(URI.create("ws://websocket.example.com"), listener);
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   531
     * }</pre>
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   532
     *
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   533
     * <p> A {@code WebSocket.Builder} returned from this method is not safe for
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   534
     * use by multiple threads without external synchronization.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   535
     *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   536
     * @implSpec The default implementation of this method throws
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   537
     * {@code UnsupportedOperationException}. Clients obtained through
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   538
     * {@link HttpClient#newHttpClient()} or {@link HttpClient#newBuilder()}
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   539
     * return a {@code WebSocket} builder.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   540
     *
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   541
     * @implNote Both builder and {@code WebSocket}s created with it operate in
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   542
     * a non-blocking fashion. That is, their methods do not block before
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   543
     * returning a {@code CompletableFuture}. Asynchronous tasks are executed in
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   544
     * this {@code HttpClient}'s executor.
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   545
     *
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   546
     * <p> When a {@code CompletionStage} returned from
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   547
     * {@link WebSocket.Listener#onClose Listener.onClose} completes,
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   548
     * the {@code WebSocket} will send a Close message that has the same code
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   549
     * the received message has and an empty reason.
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   550
     *
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   551
     * @return a {@code WebSocket.Builder}
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   552
     * @throws UnsupportedOperationException
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   553
     *         if this {@code HttpClient} does not provide WebSocket support
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   554
     */
48083
b1c1b4ef4be2 8191494: Refresh incubating HTTP Client
chegar
parents: 47216
diff changeset
   555
    public WebSocket.Builder newWebSocketBuilder() {
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   556
        throw new UnsupportedOperationException();
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   557
    }
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff changeset
   558
}