-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathProxyOptions.java
More file actions
139 lines (122 loc) · 3.76 KB
/
ProxyOptions.java
File metadata and controls
139 lines (122 loc) · 3.76 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
package io.vertx.httpproxy;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.codegen.json.annotations.JsonGen;
import io.vertx.core.json.JsonObject;
import io.vertx.httpproxy.cache.CacheOptions;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import static io.vertx.core.http.HttpHeaders.CONNECTION;
import static io.vertx.core.http.HttpHeaders.KEEP_ALIVE;
import static io.vertx.core.http.HttpHeaders.PROXY_AUTHENTICATE;
import static io.vertx.core.http.HttpHeaders.PROXY_AUTHORIZATION;
import static io.vertx.core.http.HttpHeaders.TRANSFER_ENCODING;
import static io.vertx.core.http.HttpHeaders.UPGRADE;
/**
* Proxy options.
*
*/
@DataObject
@JsonGen(publicConverter = false)
public class ProxyOptions {
/**
* Enable WebSocket support : {@code true}
*/
public static final boolean DEFAULT_SUPPORT_WEBSOCKET = true;
public static final Set<String> DEFAULT_HOP_BY_HOP_HEADERS = new HashSet<>(Arrays.asList(
CONNECTION.toString(),
KEEP_ALIVE.toString(),
PROXY_AUTHENTICATE.toString(),
PROXY_AUTHORIZATION.toString(),
TRANSFER_ENCODING.toString(),
UPGRADE.toString(),
"te",
"trailer"
));
private CacheOptions cacheOptions;
private boolean supportWebSocket;
private Set<String> customHopHeaders;
public ProxyOptions(JsonObject json) {
ProxyOptionsConverter.fromJson(json, this);
}
public ProxyOptions() {
supportWebSocket = DEFAULT_SUPPORT_WEBSOCKET;
customHopHeaders = DEFAULT_HOP_BY_HOP_HEADERS;
}
/**
* @return the cache options
*/
public CacheOptions getCacheOptions() {
return cacheOptions;
}
/**
* Set the cache options that configures the proxy.
*
* {@code null} cache options disables caching, by default cache is disabled.
*
* @param cacheOptions the cache options
* @return a reference to this, so the API can be used fluently
*/
public ProxyOptions setCacheOptions(CacheOptions cacheOptions) {
this.cacheOptions = cacheOptions;
return this;
}
/**
* @return whether WebSocket are supported
*/
public boolean getSupportWebSocket() {
return supportWebSocket;
}
/**
* Set whether WebSocket are supported.
*
* @param supportWebSocket {@code true} to enable WebSocket support, {@code false} otherwise
* @return a reference to this, so the API can be used fluently
*/
public ProxyOptions setSupportWebSocket(boolean supportWebSocket) {
this.supportWebSocket = supportWebSocket;
return this;
}
/**
* @return custom hop-by-hop headers
*/
public Set<String> getCustomHopHeaders() {
return customHopHeaders;
}
/**
* Sets custom hop-by-hop headers, overriding the default {@code DEFAULT_HOP_BY_HOP_HEADERS} headers.
* <p>
* <b>Warning:</b> Please read the following specification before removing or modifying
* any hop-by-hop header:
* <a href="https://datatracker.ietf.org/doc/html/rfc2616#section-13.5.1">
* RFC 2616, Section 13.5.1
* </a>
* </p>
*
* @param customHopHeaders the list of hop-by-hop headers to set
* @return a reference to this, so the API can be used fluently
*/
public ProxyOptions setCustomHopHeaders(Set<String> customHopHeaders){
this.customHopHeaders = new HashSet<String>(customHopHeaders);
return this;
}
/**
* Add a custom hop-by-hop header
*
* @param customHopHeader a custom hop-by-hop header
* @return a reference to this, so the API can be used fluently
*/
public ProxyOptions addCustomHopHeader(String customHopHeader) {
this.customHopHeaders.add(customHopHeader);
return this;
}
@Override
public String toString() {
return toJson().toString();
}
public JsonObject toJson() {
JsonObject json = new JsonObject();
ProxyOptionsConverter.toJson(this, json);
return json;
}
}