HttpTokens

Maintains a set of HTTP tokens. These tokens include headers, query- parameters, and anything else vaguely related. Both input and output are supported, though a subclass may choose to expose as read-only.

All tokens are mapped directly onto a buffer, so there is no memory allocation or copying involved.

Note that this class does not support deleting tokens, per se. Instead it marks tokens as being 'unused' by setting content to null, avoiding unwarranted reshaping of the token stack. The token stack is reused as time goes on, so there's only minor runtime overhead.

Constructors

this
this(char separator, bool inclusive)

Construct a set of tokens based upon the given delimiter, and an indication of whether said delimiter should be considered part of the left side (effectively the name).

this
this(HttpTokens source)

Clone a source set of HttpTokens

Members

Classes

FilteredTokens
class FilteredTokens

Implements a filter for iterating over tokens matching a particular name. We do it like this because there's no means of passing additional information to an opApply() method.

Functions

add
void add(cstring name, void delegate(OutputBuffer) value)

Add a token with the given name. The content is provided via the specified delegate. We stuff this name & content into the output buffer, and map a new Token onto the appropriate buffer slice.

add
void add(cstring name, cstring value)

Add a simple name/value pair to the output

addDate
void addDate(cstring name, Time value)

Add a name/date(long) pair to the output

addInt
void addInt(cstring name, int value)

Add a name/integer pair to the output

createFilter
FilteredTokens createFilter(char[] match)

Create a filter for iterating over the tokens matching a particular name.

formatTokens
char[] formatTokens(OutputBuffer dst, cstring delim)

Return a char[] representing the output. An empty array is returned if output was not configured. This perhaps could just return our 'output' buffer content, but that would not reflect deletes, or separators. Better to do it like this instead, for a small cost.

get
cstring get(cstring name, cstring ret)

Return the value of the provided header, or null if the header does not exist

getDate
Time getDate(cstring name, Time date)

Return the date value of the provided header, or the provided default-value if the header does not exist

getInt
int getInt(cstring name, int ret)

Return the integer value of the provided header, or the provided default-vaule if the header does not exist

handleMissingSeparator
bool handleMissingSeparator(cstring s, HttpToken element)

overridable method to handle the case where a token does not have a separator. Apparently, this can happen in HTTP usage

isParsed
bool isParsed()

Have tokens been parsed yet?

opApply
int opApply(int delegate(ref HttpToken) dg)

Iterate over the set of tokens

parse
void parse(InputBuffer input)

Read all tokens. Everything is mapped rather than being allocated & copied

parse
void parse(char[] content)

Parse an input string.

produce
void produce(size_t delegate(const(void)[]) consume, cstring eol)

Output the token list to the provided consumer

remove
bool remove(cstring name)

remove a token from our list. Returns false if the named token is not found.

reset
HttpTokens reset()

Reset this set of tokens.

setParsed
void setParsed(bool parsed)

Indicate whether tokens have been parsed or not.

Variables

stack
HttpStack stack;
Undocumented in source.

Meta