Module mochiweb_headers

Case preserving (but case insensitive) HTTP Header dictionary.

Copyright © 2007 Mochi Media, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Authors: Bob Ippolito (bob@mochimedia.com).

Description

Case preserving (but case insensitive) HTTP Header dictionary.

Data Types

headers()

abstract datatype: headers()

key()

key() = atom() | binary() | string()

value()

value() = atom() | binary() | string() | integer()

Function Index

default/3Insert the pair into the headers if it does not already exist.
default_from_list/2Insert pairs into the headers for keys that do not already exist.
delete_any/2Delete the header corresponding to key if it is present.
empty/0Create an empty headers structure.
enter/3Insert the pair into the headers, replacing any pre-existing key.
enter_from_list/2Insert pairs into the headers, replace any values for existing keys.
from_binary/1Transforms a raw HTTP header into a mochiweb headers structure.
from_list/1Construct a headers() from the given list.
get_combined_value/2Return the value from the given header using a case insensitive search.
get_primary_value/2Return the value of the given header up to the first semicolon using a case insensitive search.
get_value/2Return the value of the given header using a case insensitive search.
insert/3Insert the pair into the headers, merging with any pre-existing key.
lookup/2Return the case preserved key and value for the given header using a case insensitive search.
make/1Construct a headers() from the given list.
to_list/1Return the contents of the headers.

Function Details

default/3

default(K::key(), V::value(), T::headers()) -> headers()

Insert the pair into the headers if it does not already exist.

default_from_list/2

default_from_list(List::[{key(), value()}], T::headers()) -> headers()

Insert pairs into the headers for keys that do not already exist.

delete_any/2

delete_any(K::key(), T::headers()) -> headers()

Delete the header corresponding to key if it is present.

empty/0

empty() -> headers()

Create an empty headers structure.

enter/3

enter(K::key(), V::value(), T::headers()) -> headers()

Insert the pair into the headers, replacing any pre-existing key.

enter_from_list/2

enter_from_list(List::[{key(), value()}], T::headers()) -> headers()

Insert pairs into the headers, replace any values for existing keys.

from_binary/1

from_binary(RawHttpHeader::iolist()) -> headers()

Transforms a raw HTTP header into a mochiweb headers structure.

The given raw HTTP header can be one of the following:

1) A string or a binary representing a full HTTP header ending with double CRLF. Examples:
          "Content-Length: 47\r\nContent-Type: text/plain\r\n\r\n"
          <<"Content-Length: 47\r\nContent-Type: text/plain\r\n\r\n">>
2) A list of binaries or strings where each element represents a raw HTTP header line ending with a single CRLF. Examples:
          [<<"Content-Length: 47\r\n">>, <<"Content-Type: text/plain\r\n">>]
          ["Content-Length: 47\r\n", "Content-Type: text/plain\r\n"]
          ["Content-Length: 47\r\n", <<"Content-Type: text/plain\r\n">>]

from_list/1

from_list(List::[{key(), value()}]) -> headers()

Construct a headers() from the given list.

get_combined_value/2

get_combined_value(K::key(), T::headers()) -> string() | undefined

Return the value from the given header using a case insensitive search. If the value of the header is a comma-separated list where holds values are all identical, the identical value will be returned. undefined will be returned for keys that are not present or the values in the list are not the same.

NOTE: The process isn't designed for a general purpose. If you need to access all values in the combined header, please refer to '''tokenize_header_value/1'''.

Section 4.2 of the RFC 2616 (HTTP 1.1) describes multiple message-header fields with the same field-name may be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)].

get_primary_value/2

get_primary_value(K::key(), T::headers()) -> string() | undefined

Return the value of the given header up to the first semicolon using a case insensitive search. undefined will be returned for keys that are not present.

get_value/2

get_value(K::key(), T::headers()) -> string() | undefined

Return the value of the given header using a case insensitive search. undefined will be returned for keys that are not present.

insert/3

insert(K::key(), V::value(), T::headers()) -> headers()

Insert the pair into the headers, merging with any pre-existing key. A merge is done with Value = V0 ++ ", " ++ V1.

lookup/2

lookup(K::key(), T::headers()) -> {value, {key(), string()}} | none

Return the case preserved key and value for the given header using a case insensitive search. none will be returned for keys that are not present.

make/1

make(L::headers() | [{key(), value()}]) -> headers()

Construct a headers() from the given list.

to_list/1

to_list(T::headers()) -> [{key(), string()}]

Return the contents of the headers. The keys will be the exact key that was first inserted (e.g. may be an atom or binary, case is preserved).


Generated by EDoc