Represents a HTTP header field. More...
Public Member Functions | |
Field () noexcept | |
Construct empty field. | |
Field (BString &field) | |
Construct a field from the raw field value. | |
Field (const Field &other) | |
Copy constructor. | |
Field (const std::string_view &name, const std::string_view &value) | |
Construct a field with a name and a value. | |
Field (Field &&) noexcept | |
Move constructor. | |
bool | IsEmpty () const noexcept |
Check if the field is empty or has valid data. | |
const FieldName & | Name () const noexcept |
Get a const reference to the field name. | |
Field & | operator= (const Field &other) |
Copy assignment. | |
Field & | operator= (Field &&other) noexcept |
Move assignment. | |
std::string_view | RawField () const noexcept |
Get a view to the field value. | |
std::string_view | Value () const noexcept |
Get a const reference to the field value. | |
Represents a HTTP header field.
This type represents a combination of a field name and a field value. In order to be used in a HTTP header, each object must contain data that is in compliance with the HTTP specification (RFC 7230).
Some official HTTP specifications give additional guidelines for how to interpret specific fields. This class, however, does not supply any additional parsing for those specializations.
Manipulation of the contents of a HTTP field will in most cases be done through the interface of the BHttpFields object that owns this field.
This type has a special 'empty' state. This means that they do not have a key and value. Empty objects only come into existence when explicitly instantiated with the constructor with no arguments, or after the contents has been moved to another object. Empty objects cannot be added to BHttpFields objets. You do not have to check for empty fields when working with fields coming from BHttpFields objects.
|
noexcept |
Construct empty field.
This constructs an empty field. Because empty fields cannot be used in combination with a BHttpFields object, it is unlikely that you will construct these empty fields yourself.
BPrivate::Network::BHttpFields::Field::Field | ( | const std::string_view & | name, |
const std::string_view & | value | ||
) |
Construct a field with a name and a value.
The parameters are checked whether they only contain characters that are allowed by the HTTP specification.
name | The name of the header field. |
value | The value of the header field. |
std::bad_alloc | Error in case memory cannot be allocated. |
BHttpFields::InvalidInput | This error indicates that the name or the value is empty or contains invalid characters. |
BPrivate::Network::BHttpFields::Field::Field | ( | BString & | field | ) |
Construct a field from the raw field value.
The raw header field is checked to determine whether it corresponds to the the HTTP specification. Note that the raw field should not include any newline characters at the end of the string.
If succesful, the string is moved into the fields object, and the original input value will be empty.
field | The raw header field to move into the list of headers |
std::bad_alloc | Error in case memory cannot be allocated. |
BHttpFields::InvalidInput | This error indicates that the name or the value is empty or contains invalid characters. |
BPrivate::Network::BHttpFields::Field::Field | ( | const Field & | other | ) |
Copy constructor.
other | The other field to copy data from. |
std::bad_alloc | Error in case memory cannot be allocated. |
|
noexcept |
Move constructor.
After moving, the other field object will be an empty field.
|
noexcept |
Check if the field is empty or has valid data.
true | This field is empty. |
false | This field contains a valid name and value. |
|
noexcept |
Get a const reference to the field name.
Copy assignment.
other | The other field to copy data from. |
std::bad_alloc | Error in case memory cannot be allocated. |
Move assignment.
After moving, the other field object will be an empty field.
|
noexcept |
Get a view to the field value.
string_view
. The raw value does not include the line ending (\r\n).
|
noexcept |
Get a const reference to the field value.
std::string_view
.