Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientBuilderImpl.java
41171 views
1
/*
2
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package jdk.internal.net.http;
27
28
import java.net.Authenticator;
29
import java.net.CookieHandler;
30
import java.net.ProxySelector;
31
import java.time.Duration;
32
import java.util.concurrent.Executor;
33
import javax.net.ssl.SSLContext;
34
import javax.net.ssl.SSLParameters;
35
import java.net.http.HttpClient;
36
import jdk.internal.net.http.common.Utils;
37
import static java.util.Objects.requireNonNull;
38
39
public class HttpClientBuilderImpl implements HttpClient.Builder {
40
41
CookieHandler cookieHandler;
42
Duration connectTimeout;
43
HttpClient.Redirect followRedirects;
44
ProxySelector proxy;
45
Authenticator authenticator;
46
HttpClient.Version version;
47
Executor executor;
48
// Security parameters
49
SSLContext sslContext;
50
SSLParameters sslParams;
51
int priority = -1;
52
53
@Override
54
public HttpClientBuilderImpl cookieHandler(CookieHandler cookieHandler) {
55
requireNonNull(cookieHandler);
56
this.cookieHandler = cookieHandler;
57
return this;
58
}
59
60
@Override
61
public HttpClientBuilderImpl connectTimeout(Duration duration) {
62
requireNonNull(duration);
63
if (duration.isNegative() || Duration.ZERO.equals(duration))
64
throw new IllegalArgumentException("Invalid duration: " + duration);
65
this.connectTimeout = duration;
66
return this;
67
}
68
69
@Override
70
public HttpClientBuilderImpl sslContext(SSLContext sslContext) {
71
requireNonNull(sslContext);
72
this.sslContext = sslContext;
73
return this;
74
}
75
76
77
@Override
78
public HttpClientBuilderImpl sslParameters(SSLParameters sslParameters) {
79
requireNonNull(sslParameters);
80
this.sslParams = Utils.copySSLParameters(sslParameters);
81
return this;
82
}
83
84
85
@Override
86
public HttpClientBuilderImpl executor(Executor s) {
87
requireNonNull(s);
88
this.executor = s;
89
return this;
90
}
91
92
93
@Override
94
public HttpClientBuilderImpl followRedirects(HttpClient.Redirect policy) {
95
requireNonNull(policy);
96
this.followRedirects = policy;
97
return this;
98
}
99
100
101
@Override
102
public HttpClientBuilderImpl version(HttpClient.Version version) {
103
requireNonNull(version);
104
this.version = version;
105
return this;
106
}
107
108
109
@Override
110
public HttpClientBuilderImpl priority(int priority) {
111
if (priority < 1 || priority > 256) {
112
throw new IllegalArgumentException("priority must be between 1 and 256");
113
}
114
this.priority = priority;
115
return this;
116
}
117
118
@Override
119
public HttpClientBuilderImpl proxy(ProxySelector proxy) {
120
requireNonNull(proxy);
121
this.proxy = proxy;
122
return this;
123
}
124
125
126
@Override
127
public HttpClientBuilderImpl authenticator(Authenticator a) {
128
requireNonNull(a);
129
this.authenticator = a;
130
return this;
131
}
132
133
@Override
134
public HttpClient build() {
135
return HttpClientImpl.create(this);
136
}
137
}
138
139