1.1. Method Override (方法重写) 中间件

Method Override 中间件检查从请求中重写的方法,并使用它来代替原来的方法。

出于安全原因,只有 POST 方法可以被重写。

用法

e.Pre(middleware.MethodOverride())

1.1.1. 自定义配置

用法

e := echo.New()
e.Pre(middleware.MethodOverrideWithConfig(middleware.MethodOverrideConfig{
  Getter: middleware.MethodFromForm("_method"),
}))

1.1.2. 配置

MethodOverrideConfig struct {
  // Skipper defines a function to skip middleware.
  Skipper Skipper

  // Getter is a function that gets overridden method from the request.
  // Optional. Default values MethodFromHeader(echo.HeaderXHTTPMethodOverride).
  Getter MethodOverrideGetter
}

默认配置

DefaultMethodOverrideConfig = MethodOverrideConfig{
  Skipper: defaultSkipper,
  Getter:  MethodFromHeader(echo.HeaderXHTTPMethodOverride),
}

results matching ""

    No results matching ""