1919import jooby .internal .guice .TypeConverters ;
2020import jooby .internal .jetty .Jetty ;
2121import jooby .internal .mvc .Routes ;
22+ import jooby .internal .routes .HeadFilter ;
23+ import jooby .internal .routes .OptionsRouter ;
24+ import jooby .internal .routes .TraceRouter ;
2225
2326import org .slf4j .Logger ;
2427import org .slf4j .LoggerFactory ;
@@ -295,8 +298,8 @@ public class Jooby {
295298 * </p>
296299 *
297300 * <p>
298- * A module can provide his own set of properties through the {@link #config()} method. By default,
299- * this method returns an empty config object.
301+ * A module can provide his own set of properties through the {@link #config()} method. By
302+ * default, this method returns an empty config object.
300303 * </p>
301304 *
302305 * <p>
@@ -319,7 +322,8 @@ public static abstract class Module {
319322 }
320323
321324 /**
322- * Callback method to start a module. This method will be invoked after all the registered modules
325+ * Callback method to start a module. This method will be invoked after all the registered
326+ * modules
323327 * has been configured.
324328 *
325329 * @throws Exception If something goes wrong.
@@ -328,7 +332,8 @@ public void start() throws Exception {
328332 }
329333
330334 /**
331- * Callback method to stop a module and clean any resources. Invoked when the application is about
335+ * Callback method to stop a module and clean any resources. Invoked when the application is
336+ * about
332337 * to shutdown.
333338 *
334339 * @throws Exception If something goes wrong.
@@ -346,7 +351,8 @@ public void stop() throws Exception {
346351 * @param binder A guice binder. Not null.
347352 * @throws Exception If the module fails during configuration.
348353 */
349- public abstract void configure (@ Nonnull Mode mode , @ Nonnull Config config , @ Nonnull Binder binder )
354+ public abstract void configure (@ Nonnull Mode mode , @ Nonnull Config config ,
355+ @ Nonnull Binder binder )
350356 throws Exception ;
351357 }
352358
@@ -389,10 +395,18 @@ public Route.Definition use(final Filter filter) {
389395 return use ("*" , filter );
390396 }
391397
398+ public Route .Definition use (final Router router ) {
399+ return use ("*" , router );
400+ }
401+
392402 public Route .Definition use (final String path , final Filter filter ) {
393403 return route (new Route .Definition ("*" , path , filter ));
394404 }
395405
406+ public Route .Definition use (final String path , final Router router ) {
407+ return route (new Route .Definition ("*" , path , router ));
408+ }
409+
396410 /**
397411 * Define an in-line route that supports HTTP GET method:
398412 *
@@ -447,6 +461,24 @@ public Route.Definition head(final String path, final Filter filter) {
447461 return route (new Route .Definition ("HEAD" , path , filter ));
448462 }
449463
464+ public Route .Definition head (final String path ) {
465+ return route (new Route .Definition ("HEAD" , path , wrapFilter (HeadFilter .class ))
466+ .name ("*.head" ));
467+ }
468+
469+ public Route .Definition options (final String path , final Router route ) {
470+ return route (new Route .Definition ("OPTIONS" , path , route ));
471+ }
472+
473+ public Route .Definition options (final String path , final Filter filter ) {
474+ return route (new Route .Definition ("OPTIONS" , path , filter ));
475+ }
476+
477+ public Route .Definition options (final String path ) {
478+ return route (new Route .Definition ("OPTIONS" , path , wrapRouter (OptionsRouter .class ))
479+ .name ("*.options" ));
480+ }
481+
450482 /**
451483 * Define an in-line route that supports HTTP PUT method:
452484 *
@@ -493,14 +525,39 @@ public Route.Definition delete(final String path, final Filter filter) {
493525 return route (new Route .Definition ("DELETE" , path , filter ));
494526 }
495527
528+ public Route .Definition trace (final String path , final Router route ) {
529+ return route (new Route .Definition ("TRACE" , path , route ));
530+ }
531+
532+ public Route .Definition trace (final String path , final Filter filter ) {
533+ return route (new Route .Definition ("TRACE" , path , filter ));
534+ }
535+
536+ public Route .Definition trace (final String path ) {
537+ return route (new Route .Definition ("TRACE" , path , wrapRouter (TraceRouter .class ))
538+ .name ("*.trace" ));
539+ }
540+
541+ public Route .Definition connect (final String path , final Router route ) {
542+ return route (new Route .Definition ("CONNECT" , path , route ));
543+ }
544+
545+ public Route .Definition connect (final String path , final Filter filter ) {
546+ return route (new Route .Definition ("CONNECT" , path , filter ));
547+ }
548+
496549 /**
497550 * Convert an external route to an inline route.
498551 *
499- * @param route The external route class.
552+ * @param router The external route class.
500553 * @return A new inline route.
501554 */
502- private static Router wrapRouter (final Class <? extends Router > route ) {
503- return (req , resp ) -> req .getInstance (route ).handle (req , resp );
555+ private static Router wrapRouter (final Class <? extends Router > router ) {
556+ return (req , resp ) -> req .getInstance (router ).handle (req , resp );
557+ }
558+
559+ private static Filter wrapFilter (final Class <? extends Filter > filter ) {
560+ return (req , res , chain ) -> req .getInstance (filter ).handle (req , res , chain );
504561 }
505562
506563 /**
0 commit comments