Add field enumeration

This commit is contained in:
Vinnie Falco
2017-07-20 08:12:18 -07:00
parent f3bec70e65
commit 1c063f5bf6
10 changed files with 1481 additions and 0 deletions
+1
View File
@@ -8,6 +8,7 @@
#ifndef BEAST_HTTP_BUFFER_BODY_HPP
#define BEAST_HTTP_BUFFER_BODY_HPP
#include <beast/config.hpp>
#include <beast/http/error.hpp>
#include <beast/http/message.hpp>
#include <beast/http/type_traits.hpp>
+354
View File
@@ -0,0 +1,354 @@
//
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BEAST_HTTP_FIELD_HPP
#define BEAST_HTTP_FIELD_HPP
#include <beast/config.hpp>
#include <beast/core/string_view.hpp>
#include <iosfwd>
namespace beast {
namespace http {
enum class field : unsigned short
{
unknown = 0,
a_im,
accept,
accept_additions,
accept_charset,
accept_datetime,
accept_encoding,
accept_features,
accept_language,
accept_patch,
accept_post,
accept_ranges,
age,
allow,
alpn,
also_control,
alt_svc,
alt_used,
alternate_recipient,
alternates,
apply_to_redirect_ref,
approved,
archive,
archived_at,
article_names,
article_updates,
authentication_control,
authentication_info,
authentication_results,
authorization,
auto_submitted,
autoforwarded,
autosubmitted,
base,
bcc,
body,
c_ext,
c_man,
c_opt,
c_pep,
c_pep_info,
cache_control,
caldav_timezones,
cc,
close,
comments,
connection,
content_alternative,
content_base,
content_description,
content_disposition,
content_duration,
content_encoding,
content_features,
content_id,
content_identifier,
content_language,
content_length,
content_location,
content_md5,
content_range,
content_return,
content_script_type,
content_style_type,
content_transfer_encoding,
content_type,
content_version,
control,
conversion,
conversion_with_loss,
cookie,
cookie2,
dasl,
date,
date_received,
dav,
default_style,
deferred_delivery,
delivery_date,
delta_base,
depth,
derived_from,
destination,
differential_id,
digest,
discarded_x400_ipms_extensions,
discarded_x400_mts_extensions,
disclose_recipients,
disposition_notification_options,
disposition_notification_to,
distribution,
dkim_signature,
dl_expansion_history,
downgraded_bcc,
downgraded_cc,
downgraded_disposition_notification_to,
downgraded_final_recipient,
downgraded_from,
downgraded_in_reply_to,
downgraded_mail_from,
downgraded_message_id,
downgraded_original_recipient,
downgraded_rcpt_to,
downgraded_references,
downgraded_reply_to,
downgraded_resent_bcc,
downgraded_resent_cc,
downgraded_resent_from,
downgraded_resent_reply_to,
downgraded_resent_sender,
downgraded_resent_to,
downgraded_return_path,
downgraded_sender,
downgraded_to,
encoding,
encrypted,
etag,
expect,
expires,
expiry_date,
ext,
followup_to,
forwarded,
from,
generate_delivery_report,
getprofile,
hobareg,
host,
http2_settings,
if_,
if_match,
if_modified_since,
if_none_match,
if_range,
if_schedule_tag_match,
if_unmodified_since,
im,
importance,
in_reply_to,
incomplete_copy,
injection_date,
injection_info,
keep_alive,
keywords,
label,
language,
last_modified,
latest_delivery_time,
lines,
link,
list_archive,
list_help,
list_id,
list_owner,
list_post,
list_subscribe,
list_unsubscribe,
list_unsubscribe_post,
location,
lock_token,
man,
max_forwards,
memento_datetime,
message_context,
message_id,
message_type,
meter,
mime_version,
mmhs_acp127_message_identifier,
mmhs_codress_message_indicator,
mmhs_copy_precedence,
mmhs_exempted_address,
mmhs_extended_authorisation_info,
mmhs_handling_instructions,
mmhs_message_instructions,
mmhs_message_type,
mmhs_originator_plad,
mmhs_originator_reference,
mmhs_other_recipients_indicator_cc,
mmhs_other_recipients_indicator_to,
mmhs_primary_precedence,
mmhs_subject_indicator_codes,
mt_priority,
negotiate,
newsgroups,
nntp_posting_date,
nntp_posting_host,
obsoletes,
opt,
optional_www_authenticate,
ordering_type,
organization,
origin,
original_encoded_information_types,
original_from,
original_message_id,
original_recipient,
original_sender,
original_subject,
originator_return_address,
overwrite,
p3p,
path,
pep,
pep_info,
pics_label,
position,
posting_version,
pragma,
prefer,
preference_applied,
prevent_nondelivery_report,
priority,
profileobject,
protocol,
protocol_info,
protocol_query,
protocol_request,
proxy_authenticate,
proxy_authentication_info,
proxy_authorization,
proxy_features,
proxy_instruction,
public_,
public_key_pins,
public_key_pins_report_only,
range,
received,
received_spf,
redirect_ref,
references,
referer,
relay_version,
reply_by,
reply_to,
require_recipient_valid_since,
resent_bcc,
resent_cc,
resent_date,
resent_from,
resent_message_id,
resent_reply_to,
resent_sender,
resent_to,
retry_after,
return_path,
safe,
schedule_reply,
schedule_tag,
sec_websocket_accept,
sec_websocket_extensions,
sec_websocket_key,
sec_websocket_protocol,
sec_websocket_version,
security_scheme,
see_also,
sender,
sensitivity,
server,
set_cookie,
set_cookie2,
setprofile,
slug,
soapaction,
solicitation,
status_uri,
strict_transport_security,
subject,
summary,
supersedes,
surrogate_capability,
surrogate_control,
tcn,
te,
timeout,
to,
topic,
trailer,
transfer_encoding,
ttl,
upgrade,
urgency,
uri,
user_agent,
variant_vary,
vary,
vbr_info,
via,
want_digest,
warning,
www_authenticate,
x_frame_options,
x400_content_identifier,
x400_content_return,
x400_content_type,
x400_mts_identifier,
x400_originator,
x400_received,
x400_recipients,
x400_trace,
xref,
};
/** Convert a field enum to a string.
@param f The field to convert
*/
string_view
to_string(field f);
/** Attempt to convert a string to a field enum.
The string comparison is case-insensitive.
@return The corresponding field, or @ref field::unknown
if no known field matches.
*/
field
string_to_field(string_view s);
/// Write the text for a field name to an output stream.
inline
std::ostream&
operator<<(std::ostream& os, field f)
{
return os << to_string(f);
}
} // http
} // beast
#include <beast/http/impl/field.ipp>
#endif
+416
View File
@@ -0,0 +1,416 @@
//
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BEAST_HTTP_IMPL_FIELD_IPP
#define BEAST_HTTP_IMPL_FIELD_IPP
#include <beast/core/detail/ci_char_traits.hpp>
#include <algorithm>
#include <array>
#include <boost/assert.hpp>
namespace beast {
namespace http {
namespace detail {
class field_strings
{
using array_type =
std::array<string_view, 301>;
array_type v_;
public:
using const_iterator =
array_type::const_iterator;
/*
From:
https://www.iana.org/assignments/message-headers/message-headers.xhtml
*/
field_strings()
: v_({{
"<unknown-field>",
"A-IM",
"Accept",
"Accept-Additions",
"Accept-Charset",
"Accept-Datetime",
"Accept-Encoding",
"Accept-Features",
"Accept-Language",
"Accept-Patch",
"Accept-Post",
"Accept-Ranges",
"Age",
"Allow",
"ALPN",
"Also-Control",
"Alt-Svc",
"Alt-Used",
"Alternate-Recipient",
"Alternates",
"Apply-To-Redirect-Ref",
"Approved",
"Archive",
"Archived-At",
"Article-Names",
"Article-Updates",
"Authentication-Control",
"Authentication-Info",
"Authentication-Results",
"Authorization",
"Auto-Submitted",
"Autoforwarded",
"Autosubmitted",
"Base",
"Bcc",
"Body",
"C-Ext",
"C-Man",
"C-Opt",
"C-PEP",
"C-PEP-Info",
"Cache-Control",
"CalDAV-Timezones",
"Cc",
"Close",
"Comments",
"Connection",
"Content-Alternative",
"Content-Base",
"Content-Description",
"Content-Disposition",
"Content-Duration",
"Content-Encoding",
"Content-features",
"Content-ID",
"Content-Identifier",
"Content-Language",
"Content-Length",
"Content-Location",
"Content-MD5",
"Content-Range",
"Content-Return",
"Content-Script-Type",
"Content-Style-Type",
"Content-Transfer-Encoding",
"Content-Type",
"Content-Version",
"Control",
"Conversion",
"Conversion-With-Loss",
"Cookie",
"Cookie2",
"DASL",
"Date",
"Date-Received",
"DAV",
"Default-Style",
"Deferred-Delivery",
"Delivery-Date",
"Delta-Base",
"Depth",
"Derived-From",
"Destination",
"Differential-ID",
"Digest",
"Discarded-X400-IPMS-Extensions",
"Discarded-X400-MTS-Extensions",
"Disclose-Recipients",
"Disposition-Notification-Options",
"Disposition-Notification-To",
"Distribution",
"DKIM-Signature",
"DL-Expansion-History",
"Downgraded-Bcc",
"Downgraded-Cc",
"Downgraded-Disposition-Notification-To",
"Downgraded-Final-Recipient",
"Downgraded-From",
"Downgraded-In-Reply-To",
"Downgraded-Mail-From",
"Downgraded-Message-Id",
"Downgraded-Original-Recipient",
"Downgraded-Rcpt-To",
"Downgraded-References",
"Downgraded-Reply-To",
"Downgraded-Resent-Bcc",
"Downgraded-Resent-Cc",
"Downgraded-Resent-From",
"Downgraded-Resent-Reply-To",
"Downgraded-Resent-Sender",
"Downgraded-Resent-To",
"Downgraded-Return-Path",
"Downgraded-Sender",
"Downgraded-To",
"Encoding",
"Encrypted",
"ETag",
"Expect",
"Expires",
"Expiry-Date",
"Ext",
"Followup-To",
"Forwarded",
"From",
"Generate-Delivery-Report",
"GetProfile",
"Hobareg",
"Host",
"HTTP2-Settings",
"If",
"If-Match",
"If-Modified-Since",
"If-None-Match",
"If-Range",
"If-Schedule-Tag-Match",
"If-Unmodified-Since",
"IM",
"Importance",
"In-Reply-To",
"Incomplete-Copy",
"Injection-Date",
"Injection-Info",
"Keep-Alive",
"Keywords",
"Label",
"Language",
"Last-Modified",
"Latest-Delivery-Time",
"Lines",
"Link",
"List-Archive",
"List-Help",
"List-ID",
"List-Owner",
"List-Post",
"List-Subscribe",
"List-Unsubscribe",
"List-Unsubscribe-Post",
"Location",
"Lock-Token",
"Man",
"Max-Forwards",
"Memento-Datetime",
"Message-Context",
"Message-ID",
"Message-Type",
"Meter",
"MIME-Version",
"MMHS-Acp127-Message-Identifier",
"MMHS-Codress-Message-Indicator",
"MMHS-Copy-Precedence",
"MMHS-Exempted-Address",
"MMHS-Extended-Authorisation-Info",
"MMHS-Handling-Instructions",
"MMHS-Message-Instructions",
"MMHS-Message-Type",
"MMHS-Originator-PLAD",
"MMHS-Originator-Reference",
"MMHS-Other-Recipients-Indicator-CC",
"MMHS-Other-Recipients-Indicator-To",
"MMHS-Primary-Precedence",
"MMHS-Subject-Indicator-Codes",
"MT-Priority",
"Negotiate",
"Newsgroups",
"NNTP-Posting-Date",
"NNTP-Posting-Host",
"Obsoletes",
"Opt",
"Optional-WWW-Authenticate",
"Ordering-Type",
"Organization",
"Origin",
"Original-Encoded-Information-Types",
"Original-From",
"Original-Message-ID",
"Original-Recipient",
"Original-Sender",
"Original-Subject",
"Originator-Return-Address",
"Overwrite",
"P3P",
"Path",
"PEP",
"Pep-Info",
"PICS-Label",
"Position",
"Posting-Version",
"Pragma",
"Prefer",
"Preference-Applied",
"Prevent-NonDelivery-Report",
"Priority",
"ProfileObject",
"Protocol",
"Protocol-Info",
"Protocol-Query",
"Protocol-Request",
"Proxy-Authenticate",
"Proxy-Authentication-Info",
"Proxy-Authorization",
"Proxy-Features",
"Proxy-Instruction",
"Public",
"Public-Key-Pins",
"Public-Key-Pins-Report-Only",
"Range",
"Received",
"Received-SPF",
"Redirect-Ref",
"References",
"Referer",
"Relay-Version",
"Reply-By",
"Reply-To",
"Require-Recipient-Valid-Since",
"Resent-Bcc",
"Resent-Cc",
"Resent-Date",
"Resent-From",
"Resent-Message-ID",
"Resent-Reply-To",
"Resent-Sender",
"Resent-To",
"Retry-After",
"Return-Path",
"Safe",
"Schedule-Reply",
"Schedule-Tag",
"Sec-WebSocket-Accept",
"Sec-WebSocket-Extensions",
"Sec-WebSocket-Key",
"Sec-WebSocket-Protocol",
"Sec-WebSocket-Version",
"Security-Scheme",
"See-Also",
"Sender",
"Sensitivity",
"Server",
"Set-Cookie",
"Set-Cookie2",
"SetProfile",
"SLUG",
"SoapAction",
"Solicitation",
"Status-URI",
"Strict-Transport-Security",
"Subject",
"Summary",
"Supersedes",
"Surrogate-Capability",
"Surrogate-Control",
"TCN",
"TE",
"Timeout",
"To",
"Topic",
"Trailer",
"Transfer-Encoding",
"TTL",
"Upgrade",
"Urgency",
"URI",
"User-Agent",
"Variant-Vary",
"Vary",
"VBR-Info",
"Via",
"Want-Digest",
"Warning",
"WWW-Authenticate",
"X-Frame-Options",
"X400-Content-Identifier",
"X400-Content-Return",
"X400-Content-Type",
"X400-MTS-Identifier",
"X400-Originator",
"X400-Received",
"X400-Recipients",
"X400-Trace",
"Xref",
}})
{
}
std::size_t
size() const
{
return v_.size();
}
const_iterator
begin() const
{
return v_.begin();
}
const_iterator
end() const
{
return v_.end();
}
};
inline
field_strings const&
get_field_strings()
{
static field_strings const fs;
return fs;
}
template<class = void>
string_view
to_string(field f)
{
auto const& v = get_field_strings();
BOOST_ASSERT(static_cast<unsigned>(f) < v.size());
return v.begin()[static_cast<unsigned>(f)];
}
template<class = void>
field
string_to_field(string_view s)
{
auto const& v = get_field_strings();
auto const it = std::lower_bound(
v.begin(), v.end(), s,
beast::detail::ci_less{});
if(it == v.end())
return field::unknown;
if(! beast::detail::ci_equal(s, *it))
return field::unknown;
BOOST_ASSERT(beast::detail::ci_equal(s,
to_string(static_cast<field>(it - v.begin()))));
return static_cast<field>(it - v.begin());
}
} // detail
inline
string_view
to_string(field f)
{
return detail::to_string(f);
}
inline
field
string_to_field(string_view s)
{
return detail::string_to_field(s);
}
} // http
} // beast
#endif