Loading...
Searching...
No Matches
Public Member Functions | List of all members
BPrivate::Network::BHttpFields::Field Class Reference

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 FieldNameName () const noexcept
 Get a const reference to the field name.
 
Fieldoperator= (const Field &other)
 Copy assignment.
 
Fieldoperator= (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.
 

Detailed Description

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.

Since
Haiku R1

Constructor & Destructor Documentation

◆ Field() [1/5]

BPrivate::Network::BHttpFields::Field::Field ( )
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.

Since
Haiku R1

◆ Field() [2/5]

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.

Parameters
nameThe name of the header field.
valueThe value of the header field.
Exceptions
std::bad_allocError in case memory cannot be allocated.
BHttpFields::InvalidInputThis error indicates that the name or the value is empty or contains invalid characters.
Since
Haiku R1

◆ Field() [3/5]

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.

Parameters
fieldThe raw header field to move into the list of headers
Exceptions
std::bad_allocError in case memory cannot be allocated.
BHttpFields::InvalidInputThis error indicates that the name or the value is empty or contains invalid characters.
Since
Haiku R1

◆ Field() [4/5]

BPrivate::Network::BHttpFields::Field::Field ( const Field other)

Copy constructor.

Parameters
otherThe other field to copy data from.
Exceptions
std::bad_allocError in case memory cannot be allocated.
Since
Haiku R1

◆ Field() [5/5]

BPrivate::Network::BHttpFields::Field::Field ( Field &&  other)
noexcept

Move constructor.

After moving, the other field object will be an empty field.

Since
Haiku R1

Member Function Documentation

◆ IsEmpty()

bool BPrivate::Network::BHttpFields::Field::IsEmpty ( ) const
noexcept

Check if the field is empty or has valid data.

Return values
trueThis field is empty.
falseThis field contains a valid name and value.
Since
Haiku R1

◆ Name()

const FieldName & BPrivate::Network::BHttpFields::Field::Name ( ) const
noexcept

Get a const reference to the field name.

Returns
The name of the field as a BHttpFields::FieldName.
Since
Haiku R1

◆ operator=() [1/2]

Field & BPrivate::Network::BHttpFields::Field::operator= ( const Field other)

Copy assignment.

Parameters
otherThe other field to copy data from.
Exceptions
std::bad_allocError in case memory cannot be allocated.
Since
Haiku R1

◆ operator=() [2/2]

Field & BPrivate::Network::BHttpFields::Field::operator= ( Field &&  other)
noexcept

Move assignment.

After moving, the other field object will be an empty field.

Since
Haiku R1

◆ RawField()

std::string_view BPrivate::Network::BHttpFields::Field::RawField ( ) const
noexcept

Get a view to the field value.

Returns
The raw field value as a string_view. The raw value does not include the line ending (\r\n).
Since
Haiku R1

◆ Value()

std::string_view BPrivate::Network::BHttpFields::Field::Value ( ) const
noexcept

Get a const reference to the field value.

Returns
The contents of the field value as a std::string_view.
Since
Haiku R1