middleware

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoReferer is returned when a HTTPS request provides an empty Referer
	// header.
	ErrNoReferer = csrf.ErrNoReferer
	// ErrBadReferer is returned when the scheme & host in the URL do not match
	// the supplied Referer header.
	ErrBadReferer = csrf.ErrBadReferer
	// ErrNoCSRFToken is returned if no CSRF token is supplied in the request.
	ErrNoCSRFToken = csrf.ErrNoToken
	// ErrBadCSRFToken is returned if the CSRF token in the request does not match
	// the token in the session, or is otherwise malformed.
	ErrBadCSRFToken = csrf.ErrBadToken
)
View Source
var CSRF = func(next buffalo.Handler) buffalo.Handler {
	warningMsg := "middleware.CSRF is deprecated, and will be removed in v0.10.0. Use csrf.New instead."
	fmt.Println(warningMsg)
	return csrf.Middleware(next)
}

CSRF is deprecated, and will be removed in v0.10.0. Use csrf.New instead.

View Source
var PopTransaction = func(db *pop.Connection) buffalo.MiddlewareFunc {
	return func(h buffalo.Handler) buffalo.Handler {
		return func(c buffalo.Context) error {

			err := db.Transaction(func(tx *pop.Connection) error {
				start := tx.Elapsed
				defer func() {
					finished := tx.Elapsed
					elapsed := time.Duration(finished - start)
					c.LogField("db", elapsed)
				}()
				c.Set("tx", tx)
				if err := h(c); err != nil {
					return err
				}
				if res, ok := c.Response().(*buffalo.Response); ok {
					if res.Status < 200 || res.Status >= 400 {
						return errNonSuccess
					}
				}
				return nil
			})
			if err != nil && errors.Cause(err) != errNonSuccess {
				return err
			}
			return nil
		}
	}
}

PopTransaction is a piece of Buffalo middleware that wraps each request in a transaction that will automatically get committed or rolledback. It will also add a field to the log, "db", that shows the total duration spent during the request making database calls.

Functions

func AddContentType added in v0.4.7

func AddContentType(s string) buffalo.MiddlewareFunc

AddContentType will add a secondary content type to a request. If no content type is sent by the client the default will be set, otherwise the client's content type will be used.

func ParameterLogger added in v0.8.1

func ParameterLogger(next buffalo.Handler) buffalo.Handler

ParameterLogger logs form and parameter values to the logger

func SessionSaver added in v0.9.1

func SessionSaver(next buffalo.Handler) buffalo.Handler

SessionSaver is deprecated, and will be removed in v0.10.0. This now happens automatically. This middleware is no longer required.

func SetContentType added in v0.4.7

func SetContentType(s string) buffalo.MiddlewareFunc

SetContentType on the request to desired type. This will override any content type sent by the client.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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