Use field in basic_parser

This commit is contained in:
Vinnie Falco
2017-06-06 14:04:17 -07:00
parent ca25eee0dd
commit fb2f777b4d
9 changed files with 37 additions and 33 deletions

View File

@@ -890,7 +890,8 @@ class custom_parser
/// Called after receiving a header field.
void
on_field(
string_view name, // The field name
field f, // The known-field enumeration constant
string_view name, // The field name string.
string_view value, // The field value
error_code& ec); // The error returned to the caller, if any
@@ -951,7 +952,7 @@ on_response(int status, string_view reason,
template<bool isRequest>
void custom_parser<isRequest>::
on_field(string_view name,
on_field(field f, string_view name,
string_view value, error_code& ec)
{
}

View File

@@ -11,6 +11,7 @@
#include <beast/config.hpp>
#include <beast/core/error.hpp>
#include <beast/core/string_view.hpp>
#include <beast/http/field.hpp>
#include <beast/http/verb.hpp>
#include <beast/http/detail/basic_parser.hpp>
#include <boost/asio/buffer.hpp>
@@ -394,9 +395,8 @@ private:
char const* last, error_code& ec);
void
do_field(string_view name,
string_view value,
error_code& ec);
do_field(field f,
string_view value, error_code& ec);
};
} // http

View File

@@ -239,6 +239,7 @@ enum class field : unsigned short
proxy_authenticate,
proxy_authentication_info,
proxy_authorization,
proxy_connection,
proxy_features,
proxy_instruction,
public_,

View File

@@ -678,12 +678,12 @@ parse_fields(char const*& p,
auto it2 = term - 2;
detail::skip_ows(p, it2);
detail::skip_ows_rev(it2, p);
auto const value =
make_string(p, it2);
do_field(name, value, ec);
auto const f = string_to_field(name);
auto const value = make_string(p, it2);
do_field(f, value, ec);
if(ec)
return;
impl().on_field(name, value, ec);
impl().on_field(f, name, value, ec);
if(ec)
return;
p = term;
@@ -723,12 +723,12 @@ parse_fields(char const*& p,
p = term;
}
}
string_view value{
s.data(), s.size()};
do_field(name, value, ec);
auto const f = string_to_field(name);
string_view const value{s.data(), s.size()};
do_field(f, value, ec);
if(ec)
return;
impl().on_field(name, value, ec);
impl().on_field(f, name, value, ec);
if(ec)
return;
}
@@ -738,14 +738,12 @@ parse_fields(char const*& p,
template<bool isRequest, class Derived>
void
basic_parser<isRequest, Derived>::
do_field(
string_view name,
string_view value,
error_code& ec)
do_field(field f,
string_view value, error_code& ec)
{
// Connection
if(strieq("connection", name) ||
strieq("proxy-connection", name))
if(f == field::connection ||
f == field::proxy_connection)
{
auto const list = opt_token_list{value};
if(! validate_list(list))
@@ -788,7 +786,7 @@ do_field(
}
// Content-Length
if(strieq("content-length", name))
if(f == field::content_length)
{
if(f_ & flagContentLength)
{
@@ -818,7 +816,7 @@ do_field(
}
// Transfer-Encoding
if(strieq("transfer-encoding", name))
if(f == field::transfer_encoding)
{
if(f_ & flagChunked)
{
@@ -850,7 +848,7 @@ do_field(
}
// Upgrade
if(strieq("upgrade", name))
if(f == field::upgrade)
{
f_ |= flagUpgrade;
ec = {};

View File

@@ -21,7 +21,7 @@ namespace detail {
class field_strings
{
using array_type =
std::array<string_view, 301>;
std::array<string_view, 302>;
array_type v_;
@@ -257,6 +257,7 @@ public:
"Proxy-Authenticate",
"Proxy-Authentication-Info",
"Proxy-Authorization",
"Proxy-Connection",
"Proxy-Features",
"Proxy-Instruction",
"Public",

View File

@@ -204,11 +204,15 @@ private:
}
void
on_field(string_view name,
string_view value,
error_code&)
on_field(field f, string_view name,
string_view value, error_code&)
{
m_.insert(name, value);
if(f != field::unknown)
// VFALCO Note we are not preserving the
// capitalization of the field name.
m_.insert(f, value);
else
m_.insert(name, value);
}
void

View File

@@ -253,6 +253,7 @@ public:
match(field::proxy_authenticate, "Proxy-Authenticate");
match(field::proxy_authentication_info, "Proxy-Authentication-Info");
match(field::proxy_authorization, "Proxy-Authorization");
match(field::proxy_connection, "Proxy-Connection");
match(field::proxy_features, "Proxy-Features");
match(field::proxy_instruction, "Proxy-Instruction");
match(field::public_, "Public");

View File

@@ -178,9 +178,8 @@ public:
}
void
on_field(string_view,
string_view,
error_code&)
on_field(field,
string_view, string_view, error_code&)
{
}

View File

@@ -75,9 +75,8 @@ public:
}
void
on_field(string_view,
string_view,
error_code& ec)
on_field(field f, string_view,
string_view, error_code& ec)
{
got_on_field = true;
if(fc_)