-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathDsl.java
More file actions
142 lines (117 loc) · 5.3 KB
/
Dsl.java
File metadata and controls
142 lines (117 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Copyright (c) 2015-2023 AsyncHttpClient Project. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.asynchttpclient;
import org.asynchttpclient.Realm.AuthScheme;
import org.asynchttpclient.proxy.ProxyServer;
import static org.asynchttpclient.util.HttpConstants.Methods.DELETE;
import static org.asynchttpclient.util.HttpConstants.Methods.GET;
import static org.asynchttpclient.util.HttpConstants.Methods.HEAD;
import static org.asynchttpclient.util.HttpConstants.Methods.OPTIONS;
import static org.asynchttpclient.util.HttpConstants.Methods.PATCH;
import static org.asynchttpclient.util.HttpConstants.Methods.POST;
import static org.asynchttpclient.util.HttpConstants.Methods.PUT;
import static org.asynchttpclient.util.HttpConstants.Methods.TRACE;
public final class Dsl {
private Dsl() {
}
// /////////// Client ////////////////
public static AsyncHttpClient asyncHttpClient() {
return new DefaultAsyncHttpClient();
}
public static AsyncHttpClient asyncHttpClient(DefaultAsyncHttpClientConfig.Builder configBuilder) {
return new DefaultAsyncHttpClient(configBuilder.build());
}
public static AsyncHttpClient asyncHttpClient(AsyncHttpClientConfig config) {
return new DefaultAsyncHttpClient(config);
}
// /////////// Request ////////////////
public static RequestBuilder get(String url) {
return request(GET, url);
}
public static RequestBuilder put(String url) {
return request(PUT, url);
}
public static RequestBuilder post(String url) {
return request(POST, url);
}
public static RequestBuilder delete(String url) {
return request(DELETE, url);
}
public static RequestBuilder head(String url) {
return request(HEAD, url);
}
public static RequestBuilder options(String url) {
return request(OPTIONS, url);
}
public static RequestBuilder patch(String url) {
return request(PATCH, url);
}
public static RequestBuilder trace(String url) {
return request(TRACE, url);
}
public static RequestBuilder request(String method, String url) {
return new RequestBuilder(method).setUrl(url);
}
// /////////// ProxyServer ////////////////
public static ProxyServer.Builder proxyServer(String host, int port) {
return new ProxyServer.Builder(host, port);
}
// /////////// Config ////////////////
public static DefaultAsyncHttpClientConfig.Builder config() {
return new DefaultAsyncHttpClientConfig.Builder();
}
// /////////// Realm ////////////////
public static Realm.Builder realm(Realm prototype) {
return new Realm.Builder(prototype.getPrincipal(), prototype.getPassword())
.setRealmName(prototype.getRealmName())
.setAlgorithm(prototype.getAlgorithm())
.setNc(prototype.getNc())
.setNonce(prototype.getNonce())
.setCharset(prototype.getCharset())
.setOpaque(prototype.getOpaque())
.setQop(prototype.getQop())
.setScheme(prototype.getScheme())
.setUri(prototype.getUri())
.setUsePreemptiveAuth(prototype.isUsePreemptiveAuth())
.setNtlmDomain(prototype.getNtlmDomain())
.setNtlmHost(prototype.getNtlmHost())
.setUseAbsoluteURI(prototype.isUseAbsoluteURI())
.setOmitQuery(prototype.isOmitQuery())
.setServicePrincipalName(prototype.getServicePrincipalName())
.setUseCanonicalHostname(prototype.isUseCanonicalHostname())
.setCustomLoginConfig(prototype.getCustomLoginConfig())
.setLoginContextName(prototype.getLoginContextName())
.setUserhash(prototype.isUserhash())
.setSid(prototype.getSid())
.setMaxIterationCount(prototype.getMaxIterationCount());
// Note: stale is NOT copied — it's challenge-specific, always starts false
}
public static Realm.Builder realm(AuthScheme scheme, String principal, String password) {
return new Realm.Builder(principal, password).setScheme(scheme);
}
public static Realm.Builder basicAuthRealm(String principal, String password) {
return realm(AuthScheme.BASIC, principal, password);
}
public static Realm.Builder digestAuthRealm(String principal, String password) {
return realm(AuthScheme.DIGEST, principal, password);
}
public static Realm.Builder ntlmAuthRealm(String principal, String password) {
return realm(AuthScheme.NTLM, principal, password);
}
public static Realm.Builder scramSha256AuthRealm(String principal, String password) {
return realm(AuthScheme.SCRAM_SHA_256, principal, password);
}
}