Removed json(), html() and xml() predicates

Removed `json()`, `html()` and `xml()` from `RequestPredicates`, since
they were confusingly named and would also require a counterpart that
reads the request `Content-Type` instead of the `Accept` header.
This commit is contained in:
Arjen Poutsma
2017-02-15 10:57:21 +01:00
parent 7dd0f358ed
commit 36db6b2753
4 changed files with 23 additions and 124 deletions

View File

@@ -233,7 +233,7 @@ public abstract class RequestPredicates {
/**
* Return a {@code RequestPredicate} that matches if the request's path has the given extension.
* @param extension the path extension to match against
* @param extension the path extension to match against, ignoring case
* @return a predicate that matches if the request's path has the given file extension
*/
public static RequestPredicate pathExtension(String extension) {
@@ -272,48 +272,6 @@ public abstract class RequestPredicates {
};
}
/**
* Return a {@code RequestPredicate} that matches JSON requests. The returned predicate
* matches if the request has {@code application/json} in the {@code Accept} header, or if the
* request path has a {@code .json} file extension.
*
* @return a predicate that matches JSON
* @see #accept(MediaType...)
* @see #pathExtension(String)
*/
public static RequestPredicate json() {
return accept(MediaType.APPLICATION_JSON)
.or(pathExtension("json"));
}
/**
* Return a {@code RequestPredicate} that matches HTML requests. The returned predicate
* matches if the request has {@code text/html} in the {@code Accept} header, or if the request
* path has a {@code .html} file extension.
*
* @return a predicate that matches HTML requests
* @see #accept(MediaType...)
* @see #pathExtension(String)
*/
public static RequestPredicate html() {
return accept(MediaType.TEXT_HTML)
.or(pathExtension("html"));
}
/**
* Return a {@code RequestPredicate} that matches XML requests. The returned predicate
* matches if the request has {@code text/xml} or {@code application/xml} in the {@code Accept}
* header, or if the request path has a {@code .xml} file extension.
*
* @return a predicate that matches XML requests
* @see #accept(MediaType...)
* @see #pathExtension(String)
*/
public static RequestPredicate xml() {
return accept(MediaType.TEXT_XML)
.or(accept(MediaType.APPLICATION_XML))
.or(pathExtension("xml"));
}
private static class HttpMethodPredicate implements RequestPredicate {

View File

@@ -133,18 +133,6 @@ class RouterDsl {
routes += RouterFunctions.route(RequestPredicates.queryParam(name, predicate), HandlerFunction { f(it) })
}
fun json(f: (ServerRequest) -> Mono<ServerResponse>) {
routes += RouterFunctions.route(RequestPredicates.json(), HandlerFunction { f(it) })
}
fun html(f: (ServerRequest) -> Mono<ServerResponse>) {
routes += RouterFunctions.route(RequestPredicates.html(), HandlerFunction { f(it) })
}
fun xml(f: (ServerRequest) -> Mono<ServerResponse>) {
routes += RouterFunctions.route(RequestPredicates.xml(), HandlerFunction { f(it) })
}
fun resources(path: String, location: Resource) {
routes += RouterFunctions.resources(path, location)
}