public class HiddenHttpMethodFilter extends java.lang.Object implements WebFilter
WebFilter
that converts posted method parameters into HTTP methods,
retrievable via HttpRequest.getMethod()
. Since browsers currently only
support GET and POST, a common technique is to use a normal POST with an additional
hidden form field (_method
) to pass the "real" HTTP method along.
This filter reads that parameter and changes the HttpRequest.getMethod()
return value using ServerWebExchange.mutate()
.
The name of the request parameter defaults to _method
, but can be
adapted via the methodParam
property.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_METHOD_PARAM
Default method parameter:
_method |
private java.lang.String |
methodParam |
Constructor and Description |
---|
HiddenHttpMethodFilter() |
Modifier and Type | Method and Description |
---|---|
private ServerWebExchange |
convertedRequest(ServerWebExchange exchange,
java.lang.String method)
Mutate exchange into a new HTTP request method.
|
<any> |
filter(ServerWebExchange exchange,
WebFilterChain chain)
Transform an HTTP POST into another method based on
methodParam |
void |
setMethodParam(java.lang.String methodParam)
Set the parameter name to look for HTTP methods.
|
public static final java.lang.String DEFAULT_METHOD_PARAM
_method
private java.lang.String methodParam
public void setMethodParam(java.lang.String methodParam)
DEFAULT_METHOD_PARAM
public <any> filter(ServerWebExchange exchange, WebFilterChain chain)
methodParam
private ServerWebExchange convertedRequest(ServerWebExchange exchange, java.lang.String method)
exchange
- original ServerWebExchange
method
- request HTTP method based on form dataServerWebExchange