Documentation ¶
Index ¶
- func New(opt ...Option) router.WrapperFunc
- type GetterFunc
- type Option
- func FormField(fieldName string) Option
- func FormFieldWithConf(fieldName string, conf context.ConfigurationReadOnly) Option
- func Getter(customFunc GetterFunc) Option
- func Headers(headers ...string) Option
- func Methods(methods ...string) Option
- func Only(o ...Option) Option
- func Query(paramName string) Option
- func SaveOriginalMethod(requestContextKey interface{}) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(opt ...Option) router.WrapperFunc
New returns a new method override wrapper which can be registered with `Application.WrapRouter`.
Use this wrapper when you expecting clients that do not support certain HTTP operations such as DELETE or PUT for security reasons. This wrapper will accept a method, based on criteria, to override the POST method with.
Read more at: https://github.com/kataras/iris/issues/1325
Types ¶
type GetterFunc ¶
type GetterFunc func(http.ResponseWriter, *http.Request) string
GetterFunc is the type signature for declaring custom logic to extract the method name which a POST request will be replaced with.
type Option ¶
type Option func(*options)
Option sets options for a fresh method override wrapper. See `New` package-level function for more.
func FormField ¶
FormField specifies a form field to use to determinate the method to override the POST method with.
Example Field: <input type="hidden" name="_method" value="DELETE">
Defaults to: "_method".
func FormFieldWithConf ¶
func FormFieldWithConf(fieldName string, conf context.ConfigurationReadOnly) Option
FormFieldWithConf same as `FormField` but it accepts the application's configuration to parse the form based on the app core configuration.
func Getter ¶
func Getter(customFunc GetterFunc) Option
Getter sets a custom logic to use to extract the method name to override the POST method with. Defaults to nil.
func Headers ¶
Headers that client can send to specify a method to override the POST method with.
Defaults to: X-HTTP-Method X-HTTP-Method-Override X-Method-Override
func Only ¶
Only clears all default or previously registered values and uses only the "o" option(s).
The default behavior is to check for all the following by order: headers, form field, query string and any custom getter (if set). Use this method to override that behavior and use only the passed option(s) to determinate the method to override with.
Use cases:
- When need to check only for headers and ignore other fields: New(Only(Headers("X-Custom-Header")))
- When need to check only for (first) form field and (second) custom getter: New(Only(FormField("fieldName"), Getter(...)))
func Query ¶
Query specifies a url parameter name to use to determinate the method to override the POST methos with.
Example URL Query string: http://localhost:8080/path?_method=DELETE
Defaults to: "_method".
func SaveOriginalMethod ¶
func SaveOriginalMethod(requestContextKey interface{}) Option
SaveOriginalMethod will save the original method on Context.Request().Context().Value(requestContextKey).
Defaults to nil, don't save it.