methodoverride: github.com/kataras/methodoverride Index | Files

package methodoverride

import "github.com/kataras/methodoverride"

Index

Package Files

doc.go methodoverride.go

func New Uses

func New(opt ...Option) func(next http.Handler) http.Handler

New returns a new method override wrapper which can be registered on any HTTP server.

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.

type GetterFunc Uses

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 Uses

type Option func(*options)

Option sets options for a fresh method override wrapper. See `New` package-level function for more.

func FormField Uses

func FormField(fieldName string) Option

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 Getter Uses

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 Uses

func Headers(headers ...string) Option

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 Methods Uses

func Methods(methods ...string) Option

Methods can be used to add methods that can be overridden. Defaults to "POST".

func Only Uses

func Only(o ...Option) Option

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: 1. When need to check only for headers and ignore other fields:

New(Only(Headers("X-Custom-Header")))

2. When need to check only for (first) form field and (second) custom getter:

New(Only(FormField("fieldName"), Getter(...)))

func Query Uses

func Query(paramName string) Option

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 Uses

func SaveOriginalMethod(requestContextKey interface{}) Option

SaveOriginalMethod will save the original method on Request.Context().Value(requestContextKey).

Defaults to nil, don't save it.

Package methodoverride imports 5 packages (graph). Updated 2019-11-27. Refresh now. Tools for package owners.