@@ -163,11 +163,92 @@ interface Match {
163163 */
164164 @ Nonnull String getContextPath ();
165165
166+ /**
167+ * When true handles X-Forwarded-* headers by updating the values on the current context to
168+ * match what was sent in the header(s).
169+ *
170+ * This should only be installed behind a reverse proxy that has been configured to send the
171+ * <code>X-Forwarded-*</code> header, otherwise a remote user can spoof their address by
172+ * sending a header with bogus values.
173+ *
174+ * The headers that are read/set are:
175+ * <ul>
176+ * <li>X-Forwarded-For: Set/update the remote address {@link Context#setRemoteAddress(String)}.</li>
177+ * <li>X-Forwarded-Proto: Set/update request scheme {@link Context#setScheme(String)}.</li>
178+ * <li>X-Forwarded-Host: Set/update the request host {@link Context#setHost(String)}.</li>
179+ * <li>X-Forwarded-Port: Set/update the request port {@link Context#setPort(int)}.</li>
180+ * </ul>
181+ *
182+ * @return True when enabled. Default is false.
183+ */
184+ boolean isTrustProxy ();
185+
186+ /**
187+ * When true handles X-Forwarded-* headers by updating the values on the current context to
188+ * match what was sent in the header(s).
189+ *
190+ * This should only be installed behind a reverse proxy that has been configured to send the
191+ * <code>X-Forwarded-*</code> header, otherwise a remote user can spoof their address by
192+ * sending a header with bogus values.
193+ *
194+ * The headers that are read/set are:
195+ * <ul>
196+ * <li>X-Forwarded-For: Set/update the remote address {@link Context#setRemoteAddress(String)}.</li>
197+ * <li>X-Forwarded-Proto: Set/update request scheme {@link Context#setScheme(String)}.</li>
198+ * <li>X-Forwarded-Host: Set/update the request host {@link Context#setHost(String)}.</li>
199+ * <li>X-Forwarded-Port: Set/update the request port {@link Context#setPort(int)}.</li>
200+ * </ul>
201+ *
202+ * @param trustProxy True to enabled.
203+ * @return This router.
204+ */
205+ @ Nonnull Router setTrustProxy (boolean trustProxy );
206+
166207 /* ***********************************************************************************************
167208 * use(Router)
168209 * ***********************************************************************************************
169210 */
170211
212+ /**
213+ * Enabled routes for specific domain. Domain matching is done using the <code>host</code> header.
214+ *
215+ * <pre>{@code
216+ * {
217+ * domain("foo.com", new FooApp());
218+ * domain("bar.com", new BarApp());
219+ * }
220+ * }</pre>
221+ *
222+ * NOTE: if you run behind a reverse proxy you might to enabled {@link #setTrustProxy(boolean)}.
223+ *
224+ * @param domain Predicate
225+ * @param subrouter Subrouter.
226+ * @return This router.
227+ */
228+ @ Nonnull Router domain (@ Nonnull String domain , @ Nonnull Router subrouter );
229+
230+ /**
231+ * Enabled routes for specific domain. Domain matching is done using the <code>host</code> header.
232+ *
233+ * <pre>{@code
234+ * {
235+ * domain("foo.com", () -> {
236+ * get("/", ctx -> "foo");
237+ * });
238+ * domain("bar.com", () -> {
239+ * get("/", ctx -> "bar");
240+ * });
241+ * }
242+ * }</pre>
243+ *
244+ * NOTE: if you run behind a reverse proxy you might to enabled {@link #setTrustProxy(boolean)}.
245+ *
246+ * @param domain Predicate
247+ * @param body Route action.
248+ * @return This router.
249+ */
250+ @ Nonnull RouteSet domain (@ Nonnull String domain , @ Nonnull Runnable body );
251+
171252 /**
172253 * Import routes from given router. Predicate works like a filter and only when predicate pass
173254 * the routes match against the current request.
@@ -176,19 +257,45 @@ interface Match {
176257 *
177258 * <pre>{@code
178259 * {
179- *
180260 * use(ctx -> ctx.getHost().equals("foo.com"), new FooApp());
181261 * use(ctx -> ctx.getHost().equals("bar.com"), new BarApp());
182262 * }
183263 * }</pre>
184264 *
185265 * Imported routes are matched only when predicate pass.
186266 *
267+ * NOTE: if you run behind a reverse proxy you might to enabled {@link #setTrustProxy(boolean)}.
268+ *
187269 * @param predicate Context predicate.
188- * @param router Router to import.
270+ * @param subrouter Router to import.
271+ * @return This router.
272+ */
273+ @ Nonnull Router use (@ Nonnull Predicate <Context > predicate , @ Nonnull Router subrouter );
274+
275+ /**
276+ * Import routes from given action. Predicate works like a filter and only when predicate pass
277+ * the routes match against the current request.
278+ *
279+ * Example of domain predicate filter:
280+ *
281+ * <pre>{@code
282+ * {
283+ * use(ctx -> ctx.getHost().equals("foo.com"), () -> {
284+ * get("/", ctx -> "foo");
285+ * });
286+ * use(ctx -> ctx.getHost().equals("bar.com"), () -> {
287+ * get("/", ctx -> "bar");
288+ * });
289+ * }
290+ * }</pre>
291+ *
292+ * NOTE: if you run behind a reverse proxy you might to enabled {@link #setTrustProxy(boolean)}.
293+ *
294+ * @param predicate Context predicate.
295+ * @param body Route action.
189296 * @return This router.
190297 */
191- @ Nonnull Router use (@ Nonnull Predicate <Context > predicate , @ Nonnull Router router );
298+ @ Nonnull RouteSet use (@ Nonnull Predicate <Context > predicate , @ Nonnull Runnable body );
192299
193300 /**
194301 * Import all routes from the given router and prefix them with the given path.
0 commit comments