Path: blob/master/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientBuilderImpl.java
41171 views
/*1* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package jdk.internal.net.http;2627import java.net.Authenticator;28import java.net.CookieHandler;29import java.net.ProxySelector;30import java.time.Duration;31import java.util.concurrent.Executor;32import javax.net.ssl.SSLContext;33import javax.net.ssl.SSLParameters;34import java.net.http.HttpClient;35import jdk.internal.net.http.common.Utils;36import static java.util.Objects.requireNonNull;3738public class HttpClientBuilderImpl implements HttpClient.Builder {3940CookieHandler cookieHandler;41Duration connectTimeout;42HttpClient.Redirect followRedirects;43ProxySelector proxy;44Authenticator authenticator;45HttpClient.Version version;46Executor executor;47// Security parameters48SSLContext sslContext;49SSLParameters sslParams;50int priority = -1;5152@Override53public HttpClientBuilderImpl cookieHandler(CookieHandler cookieHandler) {54requireNonNull(cookieHandler);55this.cookieHandler = cookieHandler;56return this;57}5859@Override60public HttpClientBuilderImpl connectTimeout(Duration duration) {61requireNonNull(duration);62if (duration.isNegative() || Duration.ZERO.equals(duration))63throw new IllegalArgumentException("Invalid duration: " + duration);64this.connectTimeout = duration;65return this;66}6768@Override69public HttpClientBuilderImpl sslContext(SSLContext sslContext) {70requireNonNull(sslContext);71this.sslContext = sslContext;72return this;73}747576@Override77public HttpClientBuilderImpl sslParameters(SSLParameters sslParameters) {78requireNonNull(sslParameters);79this.sslParams = Utils.copySSLParameters(sslParameters);80return this;81}828384@Override85public HttpClientBuilderImpl executor(Executor s) {86requireNonNull(s);87this.executor = s;88return this;89}909192@Override93public HttpClientBuilderImpl followRedirects(HttpClient.Redirect policy) {94requireNonNull(policy);95this.followRedirects = policy;96return this;97}9899100@Override101public HttpClientBuilderImpl version(HttpClient.Version version) {102requireNonNull(version);103this.version = version;104return this;105}106107108@Override109public HttpClientBuilderImpl priority(int priority) {110if (priority < 1 || priority > 256) {111throw new IllegalArgumentException("priority must be between 1 and 256");112}113this.priority = priority;114return this;115}116117@Override118public HttpClientBuilderImpl proxy(ProxySelector proxy) {119requireNonNull(proxy);120this.proxy = proxy;121return this;122}123124125@Override126public HttpClientBuilderImpl authenticator(Authenticator a) {127requireNonNull(a);128this.authenticator = a;129return this;130}131132@Override133public HttpClient build() {134return HttpClientImpl.create(this);135}136}137138139