method

package module
v0.0.0-...-6098072 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2015 License: Apache-2.0 Imports: 3 Imported by: 0

README

method

Middlware method implements HTTP method override for Macaron.

This checks for the X-HTTP-Method-Override header and uses it if the original request method is POST. GET/HEAD methods shouldn't be overriden, hence they can't be overriden.

This is useful for REST APIs and services making use of many HTTP verbs, and when http clients don't support all of them.

API Reference

Usage

import (
	"gopkg.in/macaron.v1"
  "github.com/go-macaron/method"
)

func main() {
  m := macaron.Classic()
  m.Before(method.Override())
  m.Run()
}

Credits

This package is forked from martini-contrib/method with modifications.

License

This project is under Apache v2 License. See the LICENSE file for the full license text.

Documentation

Overview

Package method is a middleware that implements HTTP method override for Macaron.

Index

Constants

View Source
const (
	// HeaderHTTPMethodOverride is a commonly used
	// Http header to override the method.
	HeaderHTTPMethodOverride = "X-HTTP-Method-Override"
	// ParamHTTPMethodOverride is a commonly used
	// HTML form parameter to override the method.
	ParamHTTPMethodOverride = "_method"
)

Variables

View Source
var ErrInvalidOverrideMethod = errors.New("invalid override method")

ErrInvalidOverrideMethod is returned when an invalid http method was given to OverrideRequestMethod.

Functions

func Override

func Override() macaron.BeforeHandler

Override checks for the X-HTTP-Method-Override header or the HTML for parameter, `_method` and uses (if valid) the http method instead of Request.Method. This is especially useful for http clients that don't support many http verbs. It isn't secure to override e.g a GET to a POST, so only Request.Method which are POSTs are considered.

func OverrideRequestMethod

func OverrideRequestMethod(r *http.Request, method string) error

OverrideRequestMethod overrides the http request's method with the specified method.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL