/
SimpleRequestOptions.java
194 lines (170 loc) · 5.93 KB
/
SimpleRequestOptions.java
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package com.puppetlabs.http.client;
import com.puppetlabs.ssl_utils.SSLUtils;
import javax.net.ssl.SSLContext;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.util.Map;
/**
* This class represents is a wrapper around a number of options for use in
* making requests with the simple request functions contained in the Sync class.
* It is a combination of the options from ClientOptions and RequestOptions.
*
* @see com.puppetlabs.http.client.ClientOptions#ClientOptions(javax.net.ssl.SSLContext, String, String, String, String[], String[], boolean, boolean, boolean, int, int, int, int)
* @see com.puppetlabs.http.client.RequestOptions#RequestOptions(java.net.URI, java.util.Map, Object, boolean, ResponseBodyType)
*/
public class SimpleRequestOptions {
private URI uri;
private Map<String, String> headers;
private SSLContext sslContext;
private String sslCert;
private String sslKey;
private String sslCaCert;
private String[] sslProtocols;
private String[] sslCipherSuites;
private boolean insecure = false;
private Object body;
private CompressType requestBodyCompression = CompressType.NONE;
private boolean decompressBody = true;
private ResponseBodyType as = ResponseBodyType.STREAM;
private boolean forceRedirects = false;
private boolean followRedirects = true;
private int connectTimeoutMilliseconds = -1;
private int socketTimeoutMilliseconds = -1;
/**
* Constructor for SimpleRequestOptions. When this constructor is used,
* insecure and forceRedirects default to false, and followRedirects and decompressBody
* default to true. as defaults to ResponseBodyType.STREAM.
* @param url the URL against which to make the HTTP request
* @throws URISyntaxException
*/
public SimpleRequestOptions (String url) throws URISyntaxException {
this.uri = new URI(url);
}
/**
* Constructor for SimpleRequestOptions. When this constructor is used,
* insecure and forceRedirects default to false, and followRedirects and decompressBody
* default to true. as defaults to ResponseBodyType.STREAM.
* @param uri the URI against which to make the HTTP request
*/
public SimpleRequestOptions(URI uri) {
this.uri = uri;
}
public URI getUri() {
return uri;
}
public SimpleRequestOptions setUri(URI uri) {
this.uri = uri;
return this;
}
public Map<String, String> getHeaders() {
return headers;
}
public SimpleRequestOptions setHeaders(Map<String, String> headers) {
this.headers = headers;
return this;
}
public SSLContext getSslContext() {
return sslContext;
}
public SimpleRequestOptions setSslContext(SSLContext sslContext) {
this.sslContext = sslContext;
return this;
}
public String getSslCert() {
return sslCert;
}
public SimpleRequestOptions setSslCert(String sslCert) {
this.sslCert = sslCert;
return this;
}
public String getSslKey() {
return sslKey;
}
public SimpleRequestOptions setSslKey(String sslKey) {
this.sslKey = sslKey;
return this;
}
public String getSslCaCert() {
return sslCaCert;
}
public SimpleRequestOptions setSslCaCert(String sslCaCert) {
this.sslCaCert = sslCaCert;
return this;
}
public String[] getSslProtocols() {
return sslProtocols;
}
public SimpleRequestOptions setSslProtocols(String[] sslProtocols) {
this.sslProtocols = sslProtocols;
return this;
}
public String[] getSslCipherSuites() {
return sslCipherSuites;
}
public SimpleRequestOptions setSslCipherSuites(String[] sslCipherSuites) {
this.sslCipherSuites = sslCipherSuites;
return this;
}
public boolean getInsecure() {
return insecure;
}
public SimpleRequestOptions setInsecure(boolean insecure) {
this.insecure = insecure;
return this;
}
public Object getBody() {
return body;
}
public SimpleRequestOptions setBody(Object body) {
this.body = body;
return this;
}
public boolean getDecompressBody() { return decompressBody; }
public SimpleRequestOptions setDecompressBody(boolean decompressBody) {
this.decompressBody = decompressBody;
return this;
}
public CompressType getCompressRequestBody() {
return requestBodyCompression;
}
public SimpleRequestOptions setRequestBodyCompression(
CompressType requestBodyCompression) {
this.requestBodyCompression = requestBodyCompression;
return this;
}
public ResponseBodyType getAs() {
return as;
}
public SimpleRequestOptions setAs(ResponseBodyType as) {
this.as = as;
return this;
}
public boolean getForceRedirects() { return forceRedirects; }
public SimpleRequestOptions setForceRedirects(boolean forceRedirects) {
this.forceRedirects = forceRedirects;
return this;
}
public boolean getFollowRedirects() { return followRedirects; }
public SimpleRequestOptions setFollowRedirects(boolean followRedirects) {
this.followRedirects = followRedirects;
return this;
}
public int getConnectTimeoutMilliseconds() {
return connectTimeoutMilliseconds;
}
public SimpleRequestOptions setConnectTimeoutMilliseconds(
int connectTimeoutMilliseconds) {
this.connectTimeoutMilliseconds = connectTimeoutMilliseconds;
return this;
}
public int getSocketTimeoutMilliseconds() {
return socketTimeoutMilliseconds;
}
public SimpleRequestOptions setSocketTimeoutMilliseconds(
int socketTimeoutMilliseconds) {
this.socketTimeoutMilliseconds = socketTimeoutMilliseconds;
return this;
}
}