org.springframework.web.filter.reactive

Class HiddenHttpMethodFilter

  • java.lang.Object
    • org.springframework.web.filter.reactive.HiddenHttpMethodFilter
  • All Implemented Interfaces:
    WebFilter


    public class HiddenHttpMethodFilter
    extends java.lang.Object
    implements WebFilter
    Reactive 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 methodParamName property.

    Since:
    5.0
    Author:
    Greg Turnquist, Rossen Stoyanchev
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String DEFAULT_METHOD_PARAMETER_NAME
      Default name of the form parameter with the HTTP method to use.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      reactor.core.publisher.Mono<java.lang.Void> filter(ServerWebExchange exchange, WebFilterChain chain)
      Transform an HTTP POST into another method based on methodParamName.
      void setMethodParamName(java.lang.String methodParamName)
      Set the name of the form parameter with the HTTP method to use.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_METHOD_PARAMETER_NAME

        public static final java.lang.String DEFAULT_METHOD_PARAMETER_NAME
        Default name of the form parameter with the HTTP method to use.
        See Also:
        Constant Field Values
    • Constructor Detail

      • HiddenHttpMethodFilter

        public HiddenHttpMethodFilter()
    • Method Detail

      • setMethodParamName

        public void setMethodParamName(java.lang.String methodParamName)
        Set the name of the form parameter with the HTTP method to use.

        By default this is set to "_method".

      • filter

        public reactor.core.publisher.Mono<java.lang.Void> filter(ServerWebExchange exchange,
                                                                  WebFilterChain chain)
        Transform an HTTP POST into another method based on methodParamName.
        Specified by:
        filter in interface WebFilter
        Parameters:
        exchange - the current server exchange
        chain - provides a way to delegate to the next filter
        Returns:
        Mono<Void> to indicate when request processing is complete