Parse array of name/value pairs as references to original data. More...

#include <BasicHttpHeaders.h>

Inheritance diagram for BasicHttpHeaders:
[legend]
Collaboration diagram for BasicHttpHeaders:
[legend]

Classes

struct  Header
 

Public Member Functions

 BasicHttpHeaders ()
 
void clear ()
 Reset to default state. More...
 
HttpError parse (char *data, size_t len, http_parser_type type=HTTP_BOTH)
 Parse header data into name/value pairs. More...
 
const Headeroperator[] (unsigned i) const
 
String toString (unsigned i) const
 
const char *& operator[] (const char *name)
 
unsigned count () const
 Get number of parsed headers. More...
 
const char * operator[] (const char *name) const
 Find a header by name. More...
 
const char * operator[] (HttpHeaderFieldName name) const
 
bool contains (const char *name) const
 
bool contains (HttpHeaderFieldName name) const
 
http_parser_type type () const
 Get the type of message parsed. More...
 
HttpMethod method () const
 Obtain request method. More...
 
void setMethod (HttpMethod method)
 
HttpStatus status () const
 Obtain response status. More...
 
unsigned contentLength () const
 Obtain content length field value. More...
 
- Public Member Functions inherited from HttpHeaderFields
Flags getFlags (HttpHeaderFieldName name) const
 Get flags (if any) for given header field. More...
 
String toString (HttpHeaderFieldName name) const
 
String toString (HttpHeaderFieldName name, const String &value) const
 
HttpHeaderFieldName fromString (const String &name) const
 Find the enumerated value for the given field name string. More...
 
HttpHeaderFieldName findOrCreate (const String &name)
 Find the enumerated value for the given field name string, create a custom entry if not found. More...
 
void clear ()
 

Static Public Attributes

static constexpr size_t maxValues = 16
 

Additional Inherited Members

- Public Types inherited from HttpHeaderFields
enum  Flag { Flag::Multi }
 Flag values providing additional information about header fields. More...
 
using Flags = BitSet< uint8_t, Flag, 1 >
 
- Static Public Member Functions inherited from HttpHeaderFields
static String toString (const String &name, const String &value)
 Produce a string for output in the HTTP header, with line ending. More...
 

Detailed Description

Parse array of name/value pairs as references to original data.

Note
When parsing a fixed block of text we don't need to make copies of the content, just nul-terminate the elements and build a list of references.

Constructor & Destructor Documentation

◆ BasicHttpHeaders()

BasicHttpHeaders::BasicHttpHeaders ( )
inline

Member Function Documentation

◆ clear()

void BasicHttpHeaders::clear ( )

Reset to default state.

◆ contains() [1/2]

bool BasicHttpHeaders::contains ( const char *  name) const
inline

◆ contains() [2/2]

bool BasicHttpHeaders::contains ( HttpHeaderFieldName  name) const
inline

◆ contentLength()

unsigned BasicHttpHeaders::contentLength ( ) const
inline

Obtain content length field value.

◆ count()

unsigned BasicHttpHeaders::count ( ) const
inline

Get number of parsed headers.

◆ method()

HttpMethod BasicHttpHeaders::method ( ) const
inline

Obtain request method.

◆ operator[]() [1/4]

const Header& BasicHttpHeaders::operator[] ( unsigned  i) const
inline

◆ operator[]() [2/4]

const char*& BasicHttpHeaders::operator[] ( const char *  name)

◆ operator[]() [3/4]

const char* BasicHttpHeaders::operator[] ( const char *  name) const

Find a header by name.

Parameters
nameCase-insensitive
Return values
constchar* If found, the value, otherwise nullptr

◆ operator[]() [4/4]

const char* BasicHttpHeaders::operator[] ( HttpHeaderFieldName  name) const
inline

◆ parse()

HttpError BasicHttpHeaders::parse ( char *  data,
size_t  len,
http_parser_type  type = HTTP_BOTH 
)

Parse header data into name/value pairs.

Parameters
data
len
typeType of headers to parse. The default (HTTP_BOTH) detects this automatically, use type() to determine which. Specifying HTTP_REQUEST or HTTP_RESPONSE will only accept the given type and fail on mismatch.
Return values
HttpErrorResult of parsing, HPE_OK on success. Can use with toString() or httpGetErrorDescription().
Note
Content of provided data is modified to insert NUL terminators on string values Use type() method to determine whether it's a request or response

◆ setMethod()

void BasicHttpHeaders::setMethod ( HttpMethod  method)
inline

◆ status()

HttpStatus BasicHttpHeaders::status ( ) const
inline

Obtain response status.

◆ toString()

String BasicHttpHeaders::toString ( unsigned  i) const
inline

◆ type()

http_parser_type BasicHttpHeaders::type ( ) const
inline

Get the type of message parsed.

Return values
http_parser_typeeither HTTP_REQUEST or HTTP_RESPONSE

Member Data Documentation

◆ maxValues

constexpr size_t BasicHttpHeaders::maxValues = 16
static

The documentation for this class was generated from the following file: