-
-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathRouterOptions.java
More file actions
307 lines (279 loc) · 10.1 KB
/
RouterOptions.java
File metadata and controls
307 lines (279 loc) · 10.1 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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package io.jooby;
/**
* Router options:
*
* <ul>
* <li>ignoreCase: Indicates whenever routing algorithm does case-sensitive matching on an
* incoming request path. Default is <code> false</code> (case sensitive).
* <li>ignoreTrailingSlash: Indicates whenever a trailing slash is ignored on an incoming request
* path.
* <li>normalizeSlash: Normalize an incoming request path by removing consecutive <code>/</code>
* (slashes).
* <li>resetHeadersOnError: Indicates whenever response headers are clear/reset in case of
* exception.
* </ul>
*
* @author edgar
* @since 2.4.0
*/
public class RouterOptions {
/**
* Detect or prevent duplicate route registrations. This option must be set before creating
* routes.
*/
private boolean failOnDuplicateRoutes = false;
/**
* Indicates whenever routing algorithm does case-sensitive matching on an incoming request path.
* Default is <code>case sensitive</code>.
*/
private boolean ignoreCase;
/** Indicates whenever a trailing slash is ignored on an incoming request path. */
private boolean ignoreTrailingSlash;
/** Normalize an incoming request path by removing multiple slash sequences. */
private boolean normalizeSlash;
/** Indicates whenever response headers are clear/reset in case of exception. */
private boolean resetHeadersOnError;
/**
* When true handles X-Forwarded-* headers by updating the values on the current context to match
* what was sent in the header(s).
*
* <p>This should only be installed behind a reverse proxy that has been configured to send the
* <code>X-Forwarded-*</code> header, otherwise a remote user can spoof their address by sending a
* header with bogus values.
*
* <p>The headers that are read/set are:
*
* <ul>
* <li>X-Forwarded-For: Set/update the remote address {@link Context#setRemoteAddress(String)}.
* <li>X-Forwarded-Proto: Set/update request scheme {@link Context#setScheme(String)}.
* <li>X-Forwarded-Host: Set/update the request host {@link Context#setHost(String)}.
* <li>X-Forwarded-Port: Set/update the request port {@link Context#setPort(int)}.
* </ul>
*/
private boolean trustProxy;
/**
* If enabled, allows to retrieve the {@link Context} object associated with the current request
* via the service registry while the request is being processed.
*/
private boolean contextAsService;
/** Default constructor. */
public RouterOptions() {}
/**
* If enabled, allows to retrieve the {@link Context} object associated with the current request
* via the service registry while the request is being processed.
*
* @return If enabled, allows to retrieve the {@link Context} object associated with the current
* request via the service registry while the request is being processed.
*/
public boolean isContextAsService() {
return contextAsService;
}
/**
* If enabled, allows to retrieve the {@link Context} object associated with the current request
* via the service registry while the request is being processed.
*
* @param contextAsService True for enabled.
* @return This options.
*/
public RouterOptions setContextAsService(boolean contextAsService) {
this.contextAsService = contextAsService;
return this;
}
/**
* Indicates whenever routing algorithm does case-sensitive matching on an incoming request path.
* Default is <code>false (case sensitive)</code>.
*
* @return True when case is ignored.
*/
public boolean isIgnoreCase() {
return ignoreCase;
}
/**
* Indicates whenever routing algorithm does case-sensitive matching on an incoming request path.
* Default is <code>false (case sensitive)</code>.
*
* @param ignoreCase True for case-insensitive.
* @return This options.
*/
public RouterOptions setIgnoreCase(boolean ignoreCase) {
this.ignoreCase = ignoreCase;
return this;
}
/**
* Detect or prevent duplicate route registrations. This option must be set before creating
* routes.
*
* @return Detect or prevent duplicate route registrations.
*/
public boolean isFailOnDuplicateRoutes() {
return failOnDuplicateRoutes;
}
/**
* Detect or prevent duplicate route registrations.
*
* @param failOnDuplicateRoutes True for detect or prevent duplicate route registrations.
* @return This options.
*/
public RouterOptions setFailOnDuplicateRoutes(boolean failOnDuplicateRoutes) {
this.failOnDuplicateRoutes = failOnDuplicateRoutes;
return this;
}
/**
* Indicates whenever routing algorithm does case-sensitive matching on an incoming request path.
* Default is <code>false (case sensitive)</code>.
*
* @param ignoreCase True for case-insensitive.
* @return This options.
*/
public RouterOptions ignoreCase(boolean ignoreCase) {
return setIgnoreCase(ignoreCase);
}
/**
* Indicates whenever a trailing slash is ignored on an incoming request path.
*
* @return Indicates whenever a trailing slash is ignored on an incoming request path.
*/
public boolean isIgnoreTrailingSlash() {
return ignoreTrailingSlash;
}
/**
* Set whenever a trailing slash is ignored on an incoming request path.
*
* @param ignoreTrailingSlash whenever a trailing slash is ignored on an incoming request path.
* @return This options.
*/
public RouterOptions setIgnoreTrailingSlash(boolean ignoreTrailingSlash) {
this.ignoreTrailingSlash = ignoreTrailingSlash;
return this;
}
/**
* Set whenever a trailing slash is ignored on an incoming request path.
*
* @param ignoreTrailingSlash whenever a trailing slash is ignored on an incoming request path.
* @return This options.
*/
public RouterOptions ignoreTrailingSlash(boolean ignoreTrailingSlash) {
return setIgnoreTrailingSlash(ignoreTrailingSlash);
}
/**
* Normalize an incoming request path by removing multiple slash sequences.
*
* @return Normalize an incoming request path by removing multiple slash sequences.
*/
public boolean isNormalizeSlash() {
return normalizeSlash;
}
/**
* Set whenever normalize an incoming request path by removing multiple slash sequences.
*
* @param normalizeSlash True for normalize a path.
* @return This options.
*/
public RouterOptions setNormalizeSlash(boolean normalizeSlash) {
this.normalizeSlash = normalizeSlash;
return this;
}
/**
* Set whenever normalize an incoming request path by removing multiple slash sequences.
*
* @param normalizeSlash True for normalize a path.
* @return This options.
*/
public RouterOptions normalizeSlash(boolean normalizeSlash) {
return setNormalizeSlash(normalizeSlash);
}
/**
* Indicates whenever response headers are clear/reset in case of exception.
*
* @return Indicates whenever response headers are clear/reset in case of exception.
*/
public boolean isResetHeadersOnError() {
return resetHeadersOnError;
}
/**
* Set whenever response headers are clear/reset in case of exception.
*
* @param resetHeadersOnError whenever response headers are clear/reset in case of exception.
* @return This options.
*/
public RouterOptions setResetHeadersOnError(boolean resetHeadersOnError) {
this.resetHeadersOnError = resetHeadersOnError;
return this;
}
/**
* Set whenever response headers are clear/reset in case of exception.
*
* @param resetHeadersOnError whenever response headers are clear/reset in case of exception.
* @return This options.
*/
public RouterOptions resetHeaderOnError(boolean resetHeadersOnError) {
return setResetHeadersOnError(resetHeadersOnError);
}
/**
* Case-sensitive with reset headers on error enabled.
*
* @return Default options.
*/
public static RouterOptions defaults() {
return new RouterOptions().resetHeaderOnError(true);
}
/**
* Case-inSensitive with reset headers on error enabled.
*
* @return Default options.
*/
public static RouterOptions caseInsensitive() {
return new RouterOptions().ignoreCase(true).resetHeaderOnError(true);
}
/**
* When true handles X-Forwarded-* headers by updating the values on the current context to match
* what was sent in the header(s).
*
* <p>This should only be installed behind a reverse proxy that has been configured to send the
* <code>X-Forwarded-*</code> header, otherwise a remote user can spoof their address by sending a
* header with bogus values.
*
* <p>The headers that are read/set are:
*
* <ul>
* <li>X-Forwarded-For: Set/update the remote address {@link Context#setRemoteAddress(String)}.
* <li>X-Forwarded-Proto: Set/update request scheme {@link Context#setScheme(String)}.
* <li>X-Forwarded-Host: Set/update the request host {@link Context#setHost(String)}.
* <li>X-Forwarded-Port: Set/update the request port {@link Context#setPort(int)}.
* </ul>
*
* @return True when enabled. Default is false.
*/
public boolean isTrustProxy() {
return trustProxy;
}
/**
* When true handles X-Forwarded-* headers by updating the values on the current context to match
* what was sent in the header(s).
*
* <p>This should only be installed behind a reverse proxy that has been configured to send the
* <code>X-Forwarded-*</code> header, otherwise a remote user can spoof their address by sending a
* header with bogus values.
*
* <p>The headers that are read/set are:
*
* <ul>
* <li>X-Forwarded-For: Set/update the remote address {@link Context#setRemoteAddress(String)}.
* <li>X-Forwarded-Proto: Set/update request scheme {@link Context#setScheme(String)}.
* <li>X-Forwarded-Host: Set/update the request host {@link Context#setHost(String)}.
* <li>X-Forwarded-Port: Set/update the request port {@link Context#setPort(int)}.
* </ul>
*
* @param trustProxy True to enable.
* @return This options.
*/
public RouterOptions setTrustProxy(boolean trustProxy) {
this.trustProxy = trustProxy;
return this;
}
}