accept - ActiveState ActiveGo 1.8
...

Package accept

import "github.com/streadway/handy/accept"
Overview
Index

Overview ▾

Package accept contains filters to reject requests without a specified Accept header with "406 Not Acceptable".

Constants

const (
    // ALL matches all media types.
    ALL = "*/*"
)

Variables

var (
    // EventStream matches media typs used for SSE events.
    EventStream = Middleware("text/event-stream", "text/*")

    // HTML matches media typs used for HTML encoded resources.
    HTML = Middleware("text/html")

    // JSON matches media typs used for JSON encoded resources.
    JSON = Middleware("application/json", "application/javascript")

    // Plain matches media typs used for plaintext resources.
    Plain = Middleware("text/plain")

    // XML matches media typs used for XML encoded resources.
    XML = Middleware("application/xhtml+xml", "application/xml")
)

func Middleware

func Middleware(mediaTypes ...string) func(http.Handler) http.Handler

Middleware returns a composable handler factory to restrict accepted media types and respond with "406 Not Acceptable" otherwise.