hdr
v0.0.0-20180504072447-bdcd46c54acf
Documentation
pkg.go.dev ↗Constants
Accept (48 declarations)
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
HeaderNewlineToSpace
var (
HeaderNewlineToSpace = strings.NewReplacer("\n", " ", "\r", " ")
)
Functions
CanonicalHeaderKey
func CanonicalHeaderKey(s string) string
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.
IsTokenRune
func IsTokenRune(r rune) bool
ParseTime
func ParseTime(text string) (time.Time, error)
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.
TrimString
func TrimString(s string) string
TrimString returns s without leading and trailing ASCII space.
ValidHeaderFieldName
func ValidHeaderFieldName(v string) bool
ValidHeaderFieldValue
func ValidHeaderFieldValue(v string) bool
Types
Header
type Header map[string][]string
A Header represents the key-value pairs in an HTTP header.
Header.Add
func (h Header) Add(key, value string)
Add adds the key, value pair to the header. It appends to any existing values associated with key.
Header.Clone
func (h Header) Clone() Header
Unified method to obtain a clone of the Header
Header.CopyFromHeader
func (h Header) CopyFromHeader(src Header)
Copies value from source
Header.Del
func (h Header) Del(key string)
Del deletes the values associated with key.
Header.Get
func (h Header) Get(key string) string
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.
Header.Set
func (h Header) Set(key, value string)
Set sets the header entries associated with key to the single element value. It replaces any existing values associated with key.
Header.Write
func (h Header) Write(w io.Writer) error
Write writes a header in wire format.
Header.WriteSubset
func (h Header) WriteSubset(w io.Writer, exclude map[string]bool) error
WriteSubset writes a header in wire format. If exclude is not nil, keys where exclude[key] == true are not written.
HeaderReader
type HeaderReader struct {
R *bufio.Reader
// contains filtered or unexported fields
}
A Reader implements convenience methods for reading requests or responses from a text protocol network connection.
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.
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"},
}
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.