forked from boostorg/beast
Use field in basic_fields and call sites
This commit is contained in:
@@ -59,7 +59,7 @@ connection_impl<_>::upgrade;
|
||||
req.version = 11;
|
||||
req.method(verb::upgrade);
|
||||
req.target("/");
|
||||
req.insert("User-Agent", "Beast");
|
||||
req.insert(field::user_agent, "Beast");
|
||||
req.prepare(connection::close, connection::upgrade);
|
||||
@endcode
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <beast/core/string_view.hpp>
|
||||
#include <beast/core/detail/ci_char_traits.hpp>
|
||||
#include <beast/http/connection.hpp>
|
||||
#include <beast/http/field.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/intrusive/list.hpp>
|
||||
#include <boost/intrusive/set.hpp>
|
||||
@@ -226,7 +227,19 @@ public:
|
||||
void
|
||||
clear() noexcept;
|
||||
|
||||
/** Remove a field.
|
||||
/** Remove zero or more known fields.
|
||||
|
||||
If more than one field with the specified name exists, all
|
||||
matching fields will be removed.
|
||||
|
||||
@param f The known field constant.
|
||||
|
||||
@return The number of fields removed.
|
||||
*/
|
||||
std::size_t
|
||||
erase(field f);
|
||||
|
||||
/** Remove zero or more fields by name.
|
||||
|
||||
If more than one field with the specified name exists, all
|
||||
matching fields will be removed.
|
||||
@@ -238,7 +251,22 @@ public:
|
||||
std::size_t
|
||||
erase(string_view name);
|
||||
|
||||
/** Insert a field value.
|
||||
/** Insert a value for a known field.
|
||||
|
||||
If a field with the same name already exists, the
|
||||
existing field is untouched and a new field value pair
|
||||
is inserted into the container.
|
||||
|
||||
@param f The known field constant.
|
||||
|
||||
@param name The name of the field.
|
||||
|
||||
@param value A string holding the value of the field.
|
||||
*/
|
||||
void
|
||||
insert(field f, string_view value);
|
||||
|
||||
/** Insert a value for a field by name.
|
||||
|
||||
If a field with the same name already exists, the
|
||||
existing field is untouched and a new field value pair
|
||||
@@ -314,16 +342,70 @@ protected:
|
||||
// for `header
|
||||
//
|
||||
|
||||
/** Returns the stored request-method string.
|
||||
|
||||
@note This is called by the @ref header implementation.
|
||||
*/
|
||||
string_view method_impl() const;
|
||||
|
||||
/** Returns the stored request-target string.
|
||||
|
||||
@note This is called by the @ref header implementation.
|
||||
*/
|
||||
string_view target_impl() const;
|
||||
|
||||
/** Returns the stored obsolete reason-phrase string.
|
||||
|
||||
@note This is called by the @ref header implementation.
|
||||
*/
|
||||
string_view reason_impl() const;
|
||||
|
||||
/** Set or clear the stored request-method string.
|
||||
|
||||
@note This is called by the @ref header implementation.
|
||||
*/
|
||||
void method_impl(string_view s);
|
||||
|
||||
/** Set or clear the stored request-target string.
|
||||
|
||||
@note This is called by the @ref header implementation.
|
||||
*/
|
||||
void target_impl(string_view s);
|
||||
|
||||
/** Set or clear the stored obsolete reason-phrase string.
|
||||
|
||||
@note This is called by the @ref header implementation.
|
||||
*/
|
||||
void reason_impl(string_view s);
|
||||
|
||||
/** Set the Content-Length field to the specified value.
|
||||
|
||||
@note This is called by the @ref header implementation.
|
||||
*/
|
||||
void content_length_impl(std::uint64_t n);
|
||||
|
||||
/** Add close to the Connection field.
|
||||
|
||||
@note This is called by the @ref header implementation.
|
||||
*/
|
||||
void connection_impl(close_t);
|
||||
|
||||
/** Add keep-alive to the Connection field.
|
||||
|
||||
@note This is called by the @ref header implementation.
|
||||
*/
|
||||
void connection_impl(keep_alive_t);
|
||||
|
||||
/** Add upgrade to the Connection field.
|
||||
|
||||
@note This is called by the @ref header implementation.
|
||||
*/
|
||||
void connection_impl(upgrade_t);
|
||||
|
||||
/** Add chunked to the Transfer-Encoding field.
|
||||
|
||||
@note This is called by the @ref header implementation.
|
||||
*/
|
||||
void chunked_impl();
|
||||
|
||||
private:
|
||||
|
||||
@@ -300,6 +300,14 @@ clear() noexcept
|
||||
list_.clear();
|
||||
}
|
||||
|
||||
template<class Allocator>
|
||||
std::size_t
|
||||
basic_fields<Allocator>::
|
||||
erase(field f)
|
||||
{
|
||||
return erase(to_string(f));
|
||||
}
|
||||
|
||||
template<class Allocator>
|
||||
std::size_t
|
||||
basic_fields<Allocator>::
|
||||
@@ -323,6 +331,14 @@ erase(string_view name)
|
||||
return n;
|
||||
}
|
||||
|
||||
template<class Allocator>
|
||||
void
|
||||
basic_fields<Allocator>::
|
||||
insert(field f, string_view value)
|
||||
{
|
||||
insert(to_string(f), value);
|
||||
}
|
||||
|
||||
template<class Allocator>
|
||||
void
|
||||
basic_fields<Allocator>::
|
||||
|
||||
@@ -103,6 +103,14 @@ size() const
|
||||
Body, decltype(*this)>{});
|
||||
}
|
||||
|
||||
template<bool isRequest, class Body, class Fields>
|
||||
void
|
||||
message<isRequest, Body, Fields>::
|
||||
content_length(std::uint64_t n)
|
||||
{
|
||||
this->content_length_impl(n);
|
||||
}
|
||||
|
||||
template<bool isRequest, class Body, class Fields>
|
||||
template<class... Args>
|
||||
void
|
||||
|
||||
@@ -559,6 +559,8 @@ struct message : header<isRequest, Fields>
|
||||
|
||||
The value of the Content-Length field will be unconditionally
|
||||
set to the specified number of octets.
|
||||
|
||||
@para n The number of octets to set for the Content-Length field.
|
||||
*/
|
||||
void
|
||||
content_length(std::uint64_t n);
|
||||
@@ -575,7 +577,7 @@ struct message : header<isRequest, Fields>
|
||||
req.version = 11;
|
||||
req.method(verb::upgrade);
|
||||
req.target("/");
|
||||
req.insert("User-Agent", "Beast");
|
||||
req.insert(field::user_agent, "Beast");
|
||||
req.prepare(connection::close, connection::upgrade);
|
||||
@endcode
|
||||
|
||||
|
||||
Reference in New Issue
Block a user