Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Poco::Net::MessageHeader Class Reference

#include <MessageHeader.h>

+ Inheritance diagram for Poco::Net::MessageHeader:
+ Collaboration diagram for Poco::Net::MessageHeader:

Public Member Functions

 MessageHeader ()
 
 MessageHeader (const MessageHeader &messageHeader)
 Creates the MessageHeader.
 
virtual ~MessageHeader ()
 
MessageHeaderoperator= (const MessageHeader &messageHeader)
 Destroys the MessageHeader.
 
virtual void write (std::ostream &ostr) const
 Assigns the content of another MessageHeader.
 
virtual void read (std::istream &istr)
 
int getFieldLimit () const
 
void setFieldLimit (int limit)
 
bool hasToken (const std::string &fieldName, const std::string &token) const
 
- Public Member Functions inherited from Poco::Net::NameValueCollection
 NameValueCollection ()
 
 NameValueCollection (const NameValueCollection &nvc)
 Creates an empty NameValueCollection.
 
 NameValueCollection (NameValueCollection &&nvc) noexcept
 Creates a NameValueCollection by copying another one.
 
virtual ~NameValueCollection ()
 Creates a NameValueCollection by moving another one.
 
NameValueCollectionoperator= (const NameValueCollection &nvc)
 Destroys the NameValueCollection.
 
NameValueCollectionoperator= (NameValueCollection &&nvc) noexcept
 Assigns the name-value pairs of another NameValueCollection to this one.
 
void swap (NameValueCollection &nvc)
 Moves the name-value pairs of another NameValueCollection to this one.
 
const std::string & operator[] (const std::string &name) const
 Swaps the NameValueCollection with another one.
 
void set (const std::string &name, const std::string &value)
 
void add (const std::string &name, const std::string &value)
 Sets the value of the (first) name-value pair with the given name.
 
const std::string & get (const std::string &name) const
 Adds a new name-value pair with the given name and value.
 
const std::string & get (const std::string &name, const std::string &defaultValue) const
 
bool has (const std::string &name) const
 
ConstIterator find (const std::string &name) const
 
ConstIterator begin () const
 
ConstIterator end () const
 
bool empty () const
 
std::size_t size () const
 Returns true iff the header does not have any content.
 
void erase (const std::string &name)
 
void clear ()
 Removes all name-value pairs with the given name.
 

Static Public Member Functions

static void splitElements (const std::string &s, std::vector< std::string > &elements, bool ignoreEmpty=true)
 
static void splitParameters (const std::string &s, std::string &value, NameValueCollection &parameters)
 
static void splitParameters (const std::string::const_iterator &begin, const std::string::const_iterator &end, NameValueCollection &parameters)
 
static void quote (const std::string &value, std::string &result, bool allowSpace=false)
 
static void decodeRFC2047 (const std::string &ins, std::string &outs, const std::string &charset="UTF-8")
 
static std::string decodeWord (const std::string &text, const std::string &charset="UTF-8")
 

Private Types

enum  Limits { MAX_NAME_LENGTH = 256 , MAX_VALUE_LENGTH = 8192 , DFL_FIELD_LIMIT = 100 }
 Decode RFC2047 string. More...
 

Private Attributes

int _fieldLimit
 

Additional Inherited Members

- Public Types inherited from Poco::Net::NameValueCollection
using HeaderMap = Poco::ListMap<std::string, std::string>
 
using Iterator = HeaderMap::Iterator
 
using ConstIterator = HeaderMap::ConstIterator
 

Detailed Description

A collection of name-value pairs that are used in various internet protocols like HTTP and SMTP.

The name is case-insensitive.

There can be more than one name-value pair with the same name.

MessageHeader supports writing and reading the header data in RFC 2822 format.

The maximum number of fields can be restricted by calling setFieldLimit(). This is useful to defend against certain kinds of denial-of-service attacks. The limit is only enforced when parsing header fields from a stream, not when programmatically adding them. The default limit is 100.

Definition at line 32 of file MessageHeader.h.

Member Enumeration Documentation

◆ Limits

Decode RFC2047 string.

Limits for basic sanity checks when reading a header

Enumerator
MAX_NAME_LENGTH 
MAX_VALUE_LENGTH 
DFL_FIELD_LIMIT 

Definition at line 154 of file MessageHeader.h.

Constructor & Destructor Documentation

◆ MessageHeader() [1/2]

Poco::Net::MessageHeader::MessageHeader ( )

◆ MessageHeader() [2/2]

Poco::Net::MessageHeader::MessageHeader ( const MessageHeader & messageHeader)

Creates the MessageHeader.

◆ ~MessageHeader()

virtual Poco::Net::MessageHeader::~MessageHeader ( )
virtual

Creates the MessageHeader by copying another one.

Member Function Documentation

◆ decodeRFC2047()

static void Poco::Net::MessageHeader::decodeRFC2047 ( const std::string & ins,
std::string & outs,
const std::string & charset = "UTF-8" )
static

Checks if the value must be quoted. If so, the value is appended to result, enclosed in double-quotes. Otherwise, the value is appended to result as-is.

◆ decodeWord()

static std::string Poco::Net::MessageHeader::decodeWord ( const std::string & text,
const std::string & charset = "UTF-8" )
static

◆ getFieldLimit()

int Poco::Net::MessageHeader::getFieldLimit ( ) const

Reads the message header from the given input stream.

See write() for the expected format. Also supported is folding of field content, according to section 2.2.3 of RFC 2822.

Reading stops at the first empty line (a line only containing \r
or
), as well as at the end of the stream.

Some basic sanity checking of the input stream is performed.

Throws a MessageException if the input stream is malformed.

◆ hasToken()

bool Poco::Net::MessageHeader::hasToken ( const std::string & fieldName,
const std::string & token ) const

Sets the maximum number of header fields allowed. This limit is used to defend certain kinds of denial-of-service attacks. Specify 0 for unlimited (not recommended).

The default limit is 100.

◆ operator=()

MessageHeader & Poco::Net::MessageHeader::operator= ( const MessageHeader & messageHeader)

Destroys the MessageHeader.

◆ quote()

static void Poco::Net::MessageHeader::quote ( const std::string & value,
std::string & result,
bool allowSpace = false )
static

Splits the given string into a collection of parameters. Parameters are expected to be separated by semicolons.

Enclosing quotes of parameter values are removed.

◆ read()

virtual void Poco::Net::MessageHeader::read ( std::istream & istr)
virtual

Writes the message header to the given output stream.

The format is one name-value pair per line, with name and value separated by a colon and lines delimited by a carriage return and a linefeed character. See RFC 2822 for details.

Reimplemented in Poco::Net::HTTPRequest, and Poco::Net::HTTPResponse.

◆ setFieldLimit()

void Poco::Net::MessageHeader::setFieldLimit ( int limit)

Returns the maximum number of header fields allowed.

See setFieldLimit() for more information.

◆ splitElements()

static void Poco::Net::MessageHeader::splitElements ( const std::string & s,
std::vector< std::string > & elements,
bool ignoreEmpty = true )
static

Returns true iff the field with the given fieldName contains the given token. Tokens in a header field are expected to be comma-separated and are case insensitive.

◆ splitParameters() [1/2]

static void Poco::Net::MessageHeader::splitParameters ( const std::string & s,
std::string & value,
NameValueCollection & parameters )
static

Splits the given string into separate elements. Elements are expected to be separated by commas.

For example, the string text/plain; q=0.5, text/html, text/x-dvi; q=0.8 is split into the elements text/plain; q=0.5 text/html text/x-dvi; q=0.8

Commas enclosed in double quotes do not split elements.

If ignoreEmpty is true, empty elements are not returned.

◆ splitParameters() [2/2]

static void Poco::Net::MessageHeader::splitParameters ( const std::string::const_iterator & begin,
const std::string::const_iterator & end,
NameValueCollection & parameters )
static

Splits the given string into a value and a collection of parameters. Parameters are expected to be separated by semicolons.

Enclosing quotes of parameter values are removed.

For example, the string multipart/mixed; boundary="MIME_boundary_01234567" is split into the value multipart/mixed and the parameter boundary -> MIME_boundary_01234567

◆ write()

virtual void Poco::Net::MessageHeader::write ( std::ostream & ostr) const
virtual

Assigns the content of another MessageHeader.

Reimplemented in Poco::Net::HTTPRequest, and Poco::Net::HTTPResponse.

Member Data Documentation

◆ _fieldLimit

int Poco::Net::MessageHeader::_fieldLimit
private

Definition at line 162 of file MessageHeader.h.


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