NetServices: Introduce BHttpFields to query and manipulate fields in HTTP messages
HTTP messages (requests and responses) have a header section that can contain HTTP headers. These headers consist of name, value pairs. This class can be used to query the headers on a response, and build a list of headers for a request. The internal implementation is designed around two different methods of storing the underlying data. For HTTP requests, the name, value pairs are stored as owned BString objects. For responses, the assumption is that there is a byte buffer that contains the data and that has the same lifetime as the BHttpFields object. The name, value pairs will then be stored as std::string_view to the underlying buffer. Still to do is: - The method to convert a BHttpFields list into a string buffer to transmit. - The method to parse a string buffer and turn it into a BHttpFields object. Change-Id: I4819db100aa1671aa7403675216a4c85fd221da7
This commit is contained in:
Executable
+585
@@ -0,0 +1,585 @@
|
||||
/*
|
||||
* Copyright 2022 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Niels Sascha Reedijk, [email protected]
|
||||
*
|
||||
* Corresponds to:
|
||||
* headers/private/netservices2/HttpFields.h hrev?????
|
||||
* src/kits/network/libnetservices2/HttpFields.cpp hrev?????
|
||||
*/
|
||||
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
|
||||
|
||||
/*!
|
||||
\file HttpFields.h
|
||||
\ingroup netservices
|
||||
\brief Provides the BHttpFields class.
|
||||
*/
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
|
||||
|
||||
/*!
|
||||
\class BHttpFields
|
||||
\ingroup netservices
|
||||
\brief Represents the field section of a HTTP header.
|
||||
|
||||
The HTTP protocol (RFC 7230) specifies that each HTTP request and response has a header. Part
|
||||
of that header is a list of fields, which are name and value pairs. The high level protocol
|
||||
defines what valid field names and field values look like. When adding or modifying field data,
|
||||
the members of this class enforce those constraints.
|
||||
|
||||
When you are processing a HTTP response, this object gives you the methods to query the headers
|
||||
in that response. When you are creating a HTTP request, this object gives you methods to add
|
||||
and modify header fields on your request. When retrieving data from the header fields, this
|
||||
data is often returned as an \c std::string_view. Please note that this object will only point
|
||||
to valid data for the lifetime of this object, which in case of a HTTP response, will be
|
||||
bound to the lifetime of the object that contains the HTTP response.
|
||||
|
||||
When adding headers, the fields are stored in the order in which they were added. However,
|
||||
when you add additional values with an existing name, the new field will be added below the
|
||||
existing field.
|
||||
|
||||
The HTTP protocol does not prohibit multiple fields with the same name, but it does note that
|
||||
semantically this is only allowed for a limited set of explicitly named headers, like the
|
||||
'Set-Cookie' field (see RFC 7230 section 3.2.2). Because most header fields will only exist
|
||||
once, the interface of this class is optimized for each header field existing only once. The
|
||||
onus is on the user to take additional steps when dealing with header fields that they know
|
||||
can occur more than once.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\class BHttpFields::InvalidInput
|
||||
\ingroup netservices
|
||||
\brief Error that represents when a string input contains characters that are incompatible with
|
||||
the HTTP specification.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\var BString BHttpFields::InvalidInput::input
|
||||
\brief The input that contains the invalid contents.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpFields::InvalidInput::InvalidInput(const char *origin, BString input)
|
||||
\brief Constructor that sets the \a origin and the invalid \a input.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn virtual BString BHttpFields::InvalidInput::DebugMessage() const override
|
||||
\brief Retrieve a debug message that contains all info in this error.
|
||||
|
||||
The output will be along the lines of:
|
||||
\code
|
||||
[Origin] Invalid format or unsupported characters in input [input]
|
||||
\endcode
|
||||
|
||||
\exception std::bad_alloc In the future this method may throw this
|
||||
exception when the memory for the debug message cannot be allocated.
|
||||
|
||||
\return A \ref BString object that contains the debug message.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn virtual const char* BHttpFields::InvalidInput::Message() const noexcept override
|
||||
\brief Get a pointer to the message describing the error.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\class BHttpFields::Field
|
||||
\ingroup netservices
|
||||
\brief 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 \ref 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 \ref BHttpFields objets. You do not have to check for empty fields when working with
|
||||
fields coming from \ref BHttpFields objects.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpFields::Field::Field() noexcept
|
||||
\brief Construct empty field.
|
||||
|
||||
This constructs an empty field. Because empty fields cannot be used in combination with a
|
||||
\ref BHttpFields object, it is unlikely that you will construct these empty fields yourself.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpFields::Field::Field(const std::string_view& name, const std::string_view& value)
|
||||
\brief Construct a field with a \a name and a \a value.
|
||||
|
||||
The parameters are checked whether they only contain characters that are allowed by the HTTP
|
||||
specification.
|
||||
|
||||
\param name The name of the header field.
|
||||
\param value The value of the header field.
|
||||
|
||||
\exception std::bad_alloc Error in case memory cannot be allocated.
|
||||
\exception BHttpFields::InvalidInput This error indicates that the \a name or the \a value
|
||||
is empty or contains invalid characters.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpFields::Field::Field(const Field &other)
|
||||
\brief Copy constructor.
|
||||
|
||||
\param other The other field to copy data from.
|
||||
|
||||
\exception std::bad_alloc Error in case memory cannot be allocated.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpFields::Field::Field(Field&& other) noexcept
|
||||
\brief Move constructor.
|
||||
|
||||
After moving, the \a other field object will be an empty field.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn Field& BHttpFields::Field::operator=(const Field &other)
|
||||
\brief Copy assignment.
|
||||
|
||||
\param other The other field to copy data from.
|
||||
|
||||
\exception std::bad_alloc Error in case memory cannot be allocated.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn Field& BHttpFields::Field::operator=(Field &&other) noexcept
|
||||
\brief Move assignment.
|
||||
|
||||
After moving, the \a other field object will be an empty field.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn const FieldName& BHttpFields::Field::Name() const noexcept
|
||||
\brief Get a const reference to the field name.
|
||||
|
||||
\return The name of the field as a \ref BHttpFields::FieldName.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn std::string_view BHttpFields::Field::Value() const noexcept
|
||||
\brief Get a const reference to the field value.
|
||||
|
||||
\return The contents of the field value as a \a std::string_view.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn bool BHttpFields::Field::IsEmpty() const noexcept
|
||||
\brief Check if the field is empty or has valid data.
|
||||
|
||||
\retval true This field is empty.
|
||||
\retval false This field contains a valid name and value.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\class BHttpFields::FieldName
|
||||
\ingroup netservices
|
||||
\brief Representation of a HTTP header name.
|
||||
|
||||
As per the HTTP specification, header fields have a name. There are limitations to which
|
||||
characters are supported. As per the specification, header field names are case insensitive.
|
||||
This means that the \c content-encoding is equal to \c Content-Encoding or even
|
||||
\c COnTenT-ENcOdING.
|
||||
|
||||
A header field name can never be empty.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpFields::FieldName::operator BString() const
|
||||
\brief Return a copy of the header name as a string.
|
||||
|
||||
\return The header name as a \ref BString object.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpFields::FieldName::operator std::string_view() const
|
||||
\brief Return a \c std::string_view over the header name.
|
||||
|
||||
\return A \c std::string_view object over the header name.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn bool BHttpFields::FieldName::operator==(const BString &other) const noexcept
|
||||
\brief Compare the header name to a string.
|
||||
|
||||
\param other The \c other string to compare it to.
|
||||
|
||||
The comparison is case-insensitive. So if this header name is set to \c Content-Encoding,
|
||||
comparing it to \c content-encoding will return \c true.
|
||||
|
||||
\retval true The current header name is equal to the \a other name.
|
||||
\retval false The current header name is different from the \a other name.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn bool BHttpFields::FieldName::operator==(const std::string_view& other) const noexcept
|
||||
\copydoc BHttpFields::FieldName::operator==(const BString &other) const noexcept
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn bool BHttpFields::FieldName::operator==(const BHttpFields::FieldName& other) const noexcept
|
||||
\copydoc BHttpFields::FieldName::operator==(const BString &other) const noexcept
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\typedef BHttpFields::ConstIterator
|
||||
\brief Define a constant iterator to iterate through the list of header fields.
|
||||
|
||||
This iterator has the same semantics as other constant iterators in the C++ standard library.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\name Constructors & Destructor
|
||||
*/
|
||||
|
||||
|
||||
//! @{
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpFields::BHttpFields()
|
||||
\brief Construct an empty list of HTTP header fields.
|
||||
|
||||
\exception std::bad_alloc Error in case memory cannot be allocated.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpFields::BHttpFields(std::initializer_list< Field > fields)
|
||||
\brief Initialize the object with a list of fields.
|
||||
|
||||
This enables you to initialize the fields with a list of \ref BHttpFields::Field objects. Any
|
||||
empty fields will be skipped. Like \ref AddField(), this constructor keeps the fields in the
|
||||
original order, though duplicate keys will be grouped together in sequence.
|
||||
|
||||
The example below will create an object with four fields, even though five fields have been
|
||||
passed in the initializer. The last header will be reorderd to follow the other
|
||||
\c Accept-Encoding header.
|
||||
\code
|
||||
const BHttpFields defaultFields = {
|
||||
{"Host"sv, "haiku-os.org"sv},
|
||||
{"Accept-Encoding"sv, "gzip"sv}
|
||||
{"Accept"sv, "*\/*"sv},
|
||||
{},
|
||||
{"Accept-Encoding"sv, "bzip2"sv}
|
||||
};
|
||||
\endcode
|
||||
|
||||
\exception std::bad_alloc Error in case memory cannot be allocated.
|
||||
\exception BHttpFields::InvalidInput This error indicates that some of the names or values in
|
||||
the list do not adhere to the HTTP specification.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpFields::BHttpFields(const BHttpFields &other)
|
||||
\brief Copy constructor.
|
||||
|
||||
\exception std::bad_alloc Error in case memory cannot be allocated.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpFields::BHttpFields(BHttpFields &&other)
|
||||
\brief Move constructor.
|
||||
|
||||
The name and value from the \a other fields object will be moved to this object. The \a other
|
||||
object will be empty, meaning it no longer has any fields.
|
||||
|
||||
\exception std::bad_alloc Error in case memory cannot be allocated.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpFields::~BHttpFields() noexcept
|
||||
\brief Destructor.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
/*!
|
||||
\name Assignment operators
|
||||
*/
|
||||
|
||||
|
||||
//! @{
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpFields& BHttpFields::operator=(BHttpFields &&other) noexcept
|
||||
\brief Move assignment operator.
|
||||
|
||||
The name and value from the \a other fields object will be moved to this object. The \a other
|
||||
object will be empty, meaning it no longer has any fields.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpFields& BHttpFields::operator=(const BHttpFields &other)
|
||||
\brief Copy assignment operator.
|
||||
|
||||
Make a new fields object with a copy of the fields of the \a other header.
|
||||
|
||||
\exception std::bad_alloc Error in case memory cannot be allocated.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
/*!
|
||||
\name List Access
|
||||
*/
|
||||
|
||||
|
||||
//! @{
|
||||
|
||||
/*!
|
||||
\fn const Field& BHttpFields::operator[](size_t index) const
|
||||
\brief Get the item at an \a index.
|
||||
|
||||
\param index The zero-based index of the item in the list of fields.
|
||||
|
||||
\return A const reference to the the field.
|
||||
|
||||
\exception BRuntimeError Error in case the index is out of bounds.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
/*!
|
||||
\name Modifying the list
|
||||
*/
|
||||
|
||||
|
||||
//! @{
|
||||
|
||||
/*!
|
||||
\fn void BHttpFields::AddField(const std::string_view &name, const std::string_view &value)
|
||||
\brief Append a field with \a name and a \a value to the list of headers.
|
||||
|
||||
The parameters are checked whether they only contain characters that are allowed by the HTTP
|
||||
specification.
|
||||
|
||||
\param name The name of the header field.
|
||||
\param value The value of the header field.
|
||||
|
||||
\exception std::bad_alloc Error in case memory cannot be allocated.
|
||||
\exception BHttpFields::InvalidInput This error indicates that the \a name or the \a value
|
||||
contains invalid characters.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn void BHttpFields::RemoveField(const std::string_view &name) noexcept
|
||||
\brief Remove all fields with the \a name.
|
||||
|
||||
If there are no fields with this name, this method does nothing. Like all operations that
|
||||
involve a field name, the name matching is case insensitive.
|
||||
|
||||
\param name The name of the field to remove.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn void BHttpFields::RemoveField(ConstIterator it) noexcept
|
||||
\brief Remove the specific field at the location of an iterator.
|
||||
|
||||
\param it A valid iterator to the item that must be removed.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn void BHttpFields::MakeEmpty() noexcept
|
||||
\brief Clear all fields from this header.
|
||||
|
||||
Removes all fields from the container.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
/*!
|
||||
\name Querying
|
||||
*/
|
||||
|
||||
|
||||
//! @{
|
||||
|
||||
|
||||
/*!
|
||||
\fn ConstIterator BHttpFields::FindField(const std::string_view &name) const noexcept
|
||||
\brief Find a field with \a name.
|
||||
|
||||
In case there are more than one fields with the same name, this container will make sure that
|
||||
these are grouped together. That means that you can use the properties of the iterator to find
|
||||
the other fields.
|
||||
|
||||
\param name The name of the field to be found.
|
||||
|
||||
\return Returns a valid iterator to the first field with \a name in this container, or
|
||||
BHttpFields::end() in case the name is not found.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn size_t BHttpFields::CountFields() const noexcept
|
||||
\brief Get the number of fields.
|
||||
|
||||
\return The number of fields in this container. If multiple fields have the same name, they
|
||||
will be counted individually.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
/*!
|
||||
\name Range-based iteration.
|
||||
Allows the usage of this object in a for loop.
|
||||
*/
|
||||
|
||||
|
||||
//! @{
|
||||
|
||||
/*!
|
||||
\fn ConstIterator BHttpFields::begin() const noexcept
|
||||
\brief Return an iterator to the first field.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn ConstIterator BHttpFields::end() const noexcept
|
||||
\brief Return an iterator to the end of the fields.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
#endif
|
||||
@@ -1,332 +0,0 @@
|
||||
/*
|
||||
* Copyright 2021 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Niels Sascha Reedijk, [email protected]
|
||||
*
|
||||
* Corresponds to:
|
||||
* headers/private/netservices2/HttpHeaders.h hrev?????
|
||||
* src/kits/network/libnetservices2/HttpHeaders.cpp hrev?????
|
||||
*/
|
||||
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
|
||||
|
||||
/*!
|
||||
\file HttpHeaders.h
|
||||
\ingroup netservices
|
||||
\brief Provides the BHttpHeader and BHttpHeaderMap classes.
|
||||
*/
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
|
||||
|
||||
/*!
|
||||
\class BHttpHeader
|
||||
\ingroup netservices
|
||||
\brief Represent a HTTP header name and value pair.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\class BHttpHeader::InvalidInput
|
||||
\ingroup netservices
|
||||
\brief Error that represents when a string input contains characters that are incompatible with
|
||||
the HTTP specification.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\var BString BHttpHeader::InvalidInput::input
|
||||
\brief The input that contains the invalid contents.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpHeader::InvalidInput::InvalidInput(const char *origin, BString input)
|
||||
\brief Constructor that sets the \a origin and the invalid \a input.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn virtual BString BHttpHeader::InvalidInput::DebugMessage() const override
|
||||
\brief Retrieve a debug message that contains all info in this error.
|
||||
|
||||
The output will be along the lines of:
|
||||
\code
|
||||
[Origin] Invalid format or unsupported characters in input [input]
|
||||
\endcode
|
||||
|
||||
\exception std::bad_alloc In the future this method may throw this
|
||||
exception when the memory for the debug message cannot be allocated.
|
||||
|
||||
\return A \ref BString object that contains the debug message.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn virtual const char* BHttpHeader::InvalidInput::Message() const noexcept override
|
||||
\brief Get a pointer to the message describing the error.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\class BHttpHeader::EmptyHeader
|
||||
\ingroup netservices
|
||||
\brief Error that is raised when the HTTP header has an empty name or value when it is
|
||||
serialized to and from text.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpHeader::EmptyHeader::EmptyHeader(const char *origin)
|
||||
\copydoc BError::BError()
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn virtual const char* BHttpHeader::EmptyHeader::Message() const noexcept override
|
||||
\brief Get a pointer to the message describing the error.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\class BHttpHeader::HeaderName
|
||||
\ingroup netservices
|
||||
\brief Representation of a HTTP header name.
|
||||
|
||||
As per the HTTP specification, header fields have a name. There are limitations to which
|
||||
characters are supported. As per the specification, header field names are case insensitive.
|
||||
This means that the \c content-encoding is equal to \c Content-Encoding or even
|
||||
\c COnTenT-ENcOdING.
|
||||
|
||||
This particular object can be empty. Headers with empty names can still be used in the
|
||||
\ref BHttpHeaderMap object, though as soon as you try to serialize them to a string, the
|
||||
\ref BHttpHeader::EmptyHeader exception will be raised.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn bool BHttpHeader::HeaderName::IsEmpty() const noexcept
|
||||
\brief Check if the header name has a value set.
|
||||
|
||||
\retval true This object is empty, meaning it is set to an empty string.
|
||||
\retval false This object has a valid header name.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpHeader::HeaderName::operator BString() const
|
||||
\brief Return a copy of the header name as a string.
|
||||
|
||||
\return The header name as a \ref BString object.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpHeader::HeaderName::operator std::string_view() const
|
||||
\brief Return a \c std::string_view over the header name.
|
||||
|
||||
\return A \c std::string_view object over the header name.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn bool BHttpHeader::HeaderName::operator==(const BString &other) const noexcept
|
||||
\brief Compare the header name to a string.
|
||||
|
||||
\param other The \c other string to compare it to.
|
||||
|
||||
The comparison is case-insensitive. So if this header name is set to \c Content-Encoding,
|
||||
comparing it to \c content-encoding will return \c true.
|
||||
|
||||
\retval true The current header name is equal to the \a other name.
|
||||
\retval false The current header name is different from the \a other name.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn bool BHttpHeader::HeaderName::operator==(const std::string_view other) const noexcept
|
||||
\copydoc BHttpHeader::HeaderName::operator==(const BString &other) const noexcept
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpHeader::BHttpHeader()
|
||||
\brief Construct an empty HTTP Header Field.
|
||||
|
||||
The name and the value of the field will both be empty.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpHeader::BHttpHeader(BHttpHeader &&other) noexcept
|
||||
\brief Move constructor.
|
||||
|
||||
The name and value from the \a other header object will be moved to this object. The \a other
|
||||
object will be empty, meaning it no longer has a name or value.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpHeader::BHttpHeader(const BHttpHeader &other)
|
||||
\brief Copy constructor.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpHeader::BHttpHeader(std::string_view name, std::string_view value)
|
||||
\brief Constructor to create a header from a \a name and a \a value.
|
||||
|
||||
The parameters are checked whether they only contain characters that are allowed by the HTTP
|
||||
specification.
|
||||
|
||||
\param name The name of the header field.
|
||||
\param value The value of the header field.
|
||||
|
||||
\exception BHttpHeader::InvalidInput This error indicates that the \a name or the \a value
|
||||
contains invalid characters.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpHeader::~BHttpHeader() noexcept
|
||||
\brief Destructor.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn bool BHttpHeader::IsEmpty() noexcept
|
||||
\brief Check if the name or the value are empty.
|
||||
|
||||
A header is considered empty when it does not have a name or a value, or neither of them. An
|
||||
empty header cannot be serialized to a string.
|
||||
|
||||
\retval true The name or value are empty.
|
||||
\retval false The name and value contain valid data.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn const HeaderName& BHttpHeader::Name() noexcept
|
||||
\brief Get the header name.
|
||||
|
||||
\return A reference to the header name object.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn std::string_view BHttpHeader::Value() noexcept
|
||||
\brief Get the header value.
|
||||
|
||||
\return A \c std::string_view to the header value.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpHeader& BHttpHeader::operator=(BHttpHeader &&other) noexcept
|
||||
\brief Move assignment operator.
|
||||
|
||||
Moves the name and value from the \a other header to this object. The \a other object will be
|
||||
empty.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn BHttpHeader& BHttpHeader::operator=(const BHttpHeader &other)
|
||||
\brief Copy assignment operator.
|
||||
|
||||
Make a new header object with a copy of the name and value of the \a other header.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn void BHttpHeader::SetName(std::string_view name)
|
||||
\brief Set the name of the header to a \a name.
|
||||
|
||||
\param name A header name with characters supported by the HTTP specification.
|
||||
|
||||
\exception BHttpHeader::InvalidInput This error indicates that the \a name contains invalid
|
||||
characters.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\fn void BHttpHeader::SetValue(std::string_view value)
|
||||
\brief Set the value of the header to a \a value.
|
||||
|
||||
\param value A header value with characters supported by the HTTP specification.
|
||||
|
||||
\exception BHttpHeader::InvalidInput This error indicates that the \a value contains invalid
|
||||
characters.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\class BHttpHeaderMap
|
||||
\ingroup netservices
|
||||
\brief Represent set of HTTP headers.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user