@@ -42,6 +42,9 @@ public interface RouterFunction<T extends ServerResponse> {
4242 */
4343 Optional <HandlerFunction <T >> route (ServerRequest request );
4444
45+
46+ // Default methods for composition and filtering
47+
4548 /**
4649 * Return a composed routing function that first invokes this function,
4750 * and then invokes the {@code other} function (of the same response type {@code T})
@@ -98,28 +101,6 @@ default RouterFunction<T> andNest(RequestPredicate predicate, RouterFunction<T>
98101 return and (RouterFunctions .nest (predicate , routerFunction ));
99102 }
100103
101- /**
102- * Filter all {@linkplain HandlerFunction handler functions} routed by this function with the given
103- * {@linkplain HandlerFilterFunction filter function}.
104- * @param <S> the filter return type
105- * @param filterFunction the filter to apply
106- * @return the filtered routing function
107- */
108- default <S extends ServerResponse > RouterFunction <S > filter (HandlerFilterFunction <T , S > filterFunction ) {
109- return new RouterFunctions .FilteredRouterFunction <>(this , filterFunction );
110- }
111-
112- /**
113- * Accept the given visitor. Default implementation calls
114- * {@link RouterFunctions.Visitor#unknown(RouterFunction)}; composed {@code RouterFunction}
115- * implementations are expected to call {@code accept} for all components that make up this
116- * router function.
117- * @param visitor the visitor to accept
118- */
119- default void accept (RouterFunctions .Visitor visitor ) {
120- visitor .unknown (this );
121- }
122-
123104 /**
124105 * Return a new routing function with the given attribute.
125106 * @param name the attribute name
@@ -154,5 +135,27 @@ default RouterFunction<T> withAttributes(Consumer<Map<String, Object>> attribute
154135 return new RouterFunctions .AttributesRouterFunction <>(this , attributes );
155136 }
156137
138+ /**
139+ * Filter all {@linkplain HandlerFunction handler functions} routed by this function
140+ * with the given {@linkplain HandlerFilterFunction filter function}.
141+ * @param <S> the filter return type
142+ * @param filterFunction the filter to apply
143+ * @return the filtered routing function
144+ */
145+ default <S extends ServerResponse > RouterFunction <S > filter (HandlerFilterFunction <T , S > filterFunction ) {
146+ return new RouterFunctions .FilteredRouterFunction <>(this , filterFunction );
147+ }
148+
149+ /**
150+ * Accept the given visitor.
151+ * <p>The default implementation calls
152+ * {@link RouterFunctions.Visitor#unknown(RouterFunction)}; composed {@code RouterFunction}
153+ * implementations are expected to call {@code accept} for all components that make up this
154+ * router function.
155+ * @param visitor the visitor to accept
156+ */
157+ default void accept (RouterFunctions .Visitor visitor ) {
158+ visitor .unknown (this );
159+ }
157160
158161}
0 commit comments