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. /// Called after receiving a header field.
void void
on_field( 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 string_view value, // The field value
error_code& ec); // The error returned to the caller, if any 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> template<bool isRequest>
void custom_parser<isRequest>:: void custom_parser<isRequest>::
on_field(string_view name, on_field(field f, string_view name,
string_view value, error_code& ec) string_view value, error_code& ec)
{ {
} }

View File

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

View File

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

View File

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

View File

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

View File

@@ -204,10 +204,14 @@ private:
} }
void void
on_field(string_view name, on_field(field f, string_view name,
string_view value, string_view value, error_code&)
error_code&)
{ {
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); m_.insert(name, value);
} }

View File

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

View File

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

View File

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