Documentation ¶
Index ¶
- Constants
- Variables
- func CanonicalHeaderKey(s string) string
- func IsTokenRune(r rune) bool
- func ParseTime(text string) (time.Time, error)
- func TrimString(s string) string
- func ValidHeaderFieldName(v string) bool
- func ValidHeaderFieldValue(v string) bool
- type Header
- func (h Header) Add(key, value string)
- func (h Header) Clone() Header
- func (h Header) CopyFromHeader(src Header)
- func (h Header) Del(key string)
- func (h Header) Get(key string) string
- func (h Header) Set(key, value string)
- func (h Header) Write(w io.Writer) error
- func (h Header) WriteSubset(w io.Writer, exclude map[string]bool) error
- type HeaderReader
Constants ¶
const ( //Headers Accept = "Accept" AcceptCharset = "Accept-Charset" AcceptEncoding = "Accept-Encoding" AcceptLanguage = "Accept-Language" AcceptRanges = "Accept-Ranges" Authorization = "Authorization" CacheControl = "Cache-Control" Cc = "Cc" Connection = "Connection" ContentEncoding = "Content-Encoding" ContentId = "Content-Id" ContentLanguage = "Content-Language" ContentLength = "Content-Length" ContentRange = "Content-Range" ContentTransferEncoding = "Content-Transfer-Encoding" ContentType = "Content-Type" CookieHeader = "Cookie" Date = "Date" DkimSignature = "Dkim-Signature" Etag = "Etag" Expires = "Expires" Expect = "Expect" From = "From" Host = "Host" IfModifiedSince = "If-Modified-Since" IfNoneMatch = "If-None-Match" InReplyTo = "In-Reply-To" LastModified = "Last-Modified" Location = "Location" MessageId = "Message-Id" MimeVersion = "Mime-Version" Pragma = "Pragma" Received = "Received" Referer = "Referer" ReturnPath = "Return-Path" ServerHeader = "Server" SetCookieHeader = "Set-Cookie" Subject = "Subject" TransferEncoding = "Transfer-Encoding" To = "To" Trailer = "Trailer" UpgradeHeader = "Upgrade" UserAgent = "User-Agent" Via = "Via" XForwardedFor = "X-Forwarded-For" XImforwards = "X-Imforwards" XPoweredBy = "X-Powered-By" TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT" )
Variables ¶
var (
HeaderNewlineToSpace = strings.NewReplacer("\n", " ", "\r", " ")
)
Functions ¶
func CanonicalHeaderKey ¶
CanonicalHeaderKey returns the canonical format of the MIME header key s. The canonicalization converts the first letter and any letter following a hyphen to upper case; the rest are converted to lowercase. For example, the canonical key for "accept-encoding" is "Accept-Encoding". MIME header keys are assumed to be ASCII only. If s contains a space or invalid header field bytes, it is returned without modifications.
func IsTokenRune ¶
func ParseTime ¶
ParseTime parses a time header (such as the Date: header), trying each of the three formats allowed by HTTP/1.1: TimeFormat, time.RFC850, and time.ANSIC.
func TrimString ¶
TrimString returns s without leading and trailing ASCII space.
func ValidHeaderFieldName ¶
func ValidHeaderFieldValue ¶
Types ¶
type Header ¶
A Header represents the key-value pairs in an HTTP header.
func (Header) Add ¶
Add adds the key, value pair to the header. It appends to any existing values associated with key.
func (Header) Get ¶
Get gets the first value associated with the given key. It is case insensitive; CanonicalHeaderKey is used to canonicalize the provided key. If there are no values associated with the key, Get returns "". To access multiple values of a key, or to use non-canonical keys, access the map directly.
func (Header) Set ¶
Set sets the header entries associated with key to the single element value. It replaces any existing values associated with key.
type HeaderReader ¶
A Reader implements convenience methods for reading requests or responses from a text protocol network connection.
func NewHeaderReader ¶
func NewHeaderReader(r *bufio.Reader) *HeaderReader
NewHeaderReader returns a new Reader reading from r.
To avoid denial of service attacks, the provided bufio.Reader should be reading from an io.LimitReader or similar Reader to bound the size of responses.
func (*HeaderReader) ReadHeader ¶
func (r *HeaderReader) ReadHeader() (Header, error)
ReadHeader reads a MIME-style header from r. The header is a sequence of possibly continued Key: Value lines ending in a blank line. The returned map m maps CanonicalHeaderKey(key) to a sequence of values in the same order encountered in the input.
For example, consider this input:
My-Key: Value 1 Long-Key: Even Longer Value My-Key: Value 2
Given that input, ReadHeader returns the map:
map[string][]string{ "My-Key": {"Value 1", "Value 2"}, "Long-Key": {"Even Longer Value"}, }
func (*HeaderReader) ReadLine ¶
func (r *HeaderReader) ReadLine() (string, error)
ReadLine reads a single line from r, eliding the final \n or \r\n from the returned string.