accept

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

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

Go to latest
Published: Mar 20, 2013 License: BSD-2-Clause Imports: 4 Imported by: 1

README

go-accept-headers

Easily handle HTTP Accept(-Charset|-Encoding|-Language) headers in Go.

This was inspired by goautoneg.

License:

Copyright (c) 2013, Ryan Rogers
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: 

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer. 
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution. 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Documentation

Overview

Package accept allows for easy handling of HTTP Accept headers. Accept-Ranges is currently not handled.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Negotiate

func Negotiate(header string, ctypes ...string) (string, error)

Negotiate returns a type that is accepted by both the header declaration, and the list of types provided. If no common types are found, an empty string is returned.

Types

type Accept

type Accept struct {
	Type, Subtype string
	Q             float64
	Extensions    map[string]string
}

Accept represents a parsed Accept(-Charset|-Encoding|-Language) header.

type AcceptSlice

type AcceptSlice []Accept

AcceptSlice is a slice of Accept.

func Parse

func Parse(header string) AcceptSlice

Parse parses a HTTP Accept(-Charset|-Encoding|-Language) header and returns AcceptSlice, sorted in decreasing order of preference. If the header lists multiple types that have the same level of preference (same specificity of type and subtype, same qvalue, and same number of extensions), the type that was listed in the header first comes first in the returned value.

See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14 for more information.

func (AcceptSlice) Accepts

func (accept AcceptSlice) Accepts(ctype string) bool

Accepts returns true if the provided type is accepted.

func (AcceptSlice) Len

func (a AcceptSlice) Len() int

Len implements the Len() method of the Sort interface.

func (AcceptSlice) Less

func (a AcceptSlice) Less(i, j int) bool

Less implements the Less() method of the Sort interface. Elements are sorted in order of decreasing preference.

func (AcceptSlice) Negotiate

func (accept AcceptSlice) Negotiate(ctypes ...string) (string, error)

Negotiate returns a type that is accepted by both the AcceptSlice, and the list of types provided. If no common types are found, an empty string is returned.

func (AcceptSlice) Swap

func (a AcceptSlice) Swap(i, j int)

Swap implements the Swap() method of the Sort interface.

Jump to

Keyboard shortcuts

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