/
RequestOptions.java
113 lines (100 loc) · 3.43 KB
/
RequestOptions.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
package com.puppetlabs.http.client;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
/**
* This class is a wrapper around a number of options for use in
* configuring an HTTP request.
*/
public class RequestOptions {
private URI uri;
private Map<String, String> headers;
private Object body;
private CompressType requestBodyCompression = CompressType.NONE;
private boolean decompressBody = true;
private ResponseBodyType as = ResponseBodyType.STREAM;
private String[] metricId;
/**
* Constructor for the RequestOptions class. When this constructor is called,
* decompressBody will default to true, and as will default to ResponseBodyType.STREAM
* @param url the URL against which to make the request
* @throws URISyntaxException
*/
public RequestOptions (String url) throws URISyntaxException { this.uri = new URI(url); }
/**
* Constructor for the RequestOptions class. When this constructor is called,
* decompressBody will default to true, and as will default to ResponseBodyType.STREAM
* @param uri the URI against which to make the request
*/
public RequestOptions(URI uri) {
this.uri = uri;
}
/**
* Constructor for the RequestOptions class
* @param uri the URI against which to make the request
* @param headers A map of headers. Can be null.
* @param body The body of the request. Can be null.
* @param decompressBody If true, an "accept-encoding" header with a value of "gzip, deflate" will be
* automatically decompressed if it contains a recognized "content-encoding" header.
* @param as Used to control the data type of the response body.
*/
public RequestOptions (URI uri,
Map<String, String> headers,
Object body,
boolean decompressBody,
ResponseBodyType as) {
this.uri = uri;
this.headers = headers;
this.body = body;
this.decompressBody = decompressBody;
this.as = as;
}
public URI getUri() {
return uri;
}
public RequestOptions setUri(URI uri) {
this.uri = uri;
return this;
}
public Map<String, String> getHeaders() {
return headers;
}
public RequestOptions setHeaders(Map<String, String> headers) {
this.headers = headers;
return this;
}
public Object getBody() {
return body;
}
public RequestOptions setBody(Object body) {
this.body = body;
return this;
}
public boolean getDecompressBody() { return decompressBody; }
public RequestOptions setDecompressBody(boolean decompressBody) {
this.decompressBody = decompressBody;
return this;
}
public CompressType getCompressRequestBody() {
return requestBodyCompression;
}
public RequestOptions setCompressRequestBody(
CompressType requestBodyCompression) {
this.requestBodyCompression = requestBodyCompression;
return this;
}
public ResponseBodyType getAs() {
return as;
}
public RequestOptions setAs(ResponseBodyType as) {
this.as = as;
return this;
}
public String[] getMetricId() {
return metricId;
}
public RequestOptions setMetricId(String[] metricId) {
this.metricId = metricId;
return this;
}
}