Restructure joyent message parser (from Node.js):

* New http::raw_parser wrapper
* Convert parser errors to error_code
* Enumeration and strings for parsed HTTP method
* Move parser engine into joyent namespace
* Rename includes to be distinct
This commit is contained in:
Vinnie Falco
2014-03-19 09:24:51 -07:00
parent d4a5c0353d
commit 78ec5ccdbc
14 changed files with 812 additions and 70 deletions

View File

@@ -21,7 +21,7 @@
#include "../../../modules/beast_core/beast_core.h" // for UnitTest
#include "http_parser.h"
#include "joyent_parser.h"
namespace beast {
@@ -36,13 +36,13 @@ ParsedURL::ParsedURL (String const& url)
std::size_t const buflen (ss.size ());
char const* const buf (ss.c_str ());
http_parser_url u;
joyent::http_parser_url u;
m_error = http_parser_parse_url (buf, buflen, false, &u);
m_error = joyent::http_parser_parse_url (buf, buflen, false, &u);
String scheme_;
String host_;
uint16 port_ (0);
std::uint16_t port_ (0);
String port_string_;
String path_;
String query_;
@@ -51,58 +51,58 @@ ParsedURL::ParsedURL (String const& url)
if (m_error == 0)
{
if ((u.field_set & (1<<UF_SCHEMA)) != 0)
if ((u.field_set & (1<<joyent::UF_SCHEMA)) != 0)
{
scheme_ = String (
buf + u.field_data [UF_SCHEMA].off,
u.field_data [UF_SCHEMA].len);
buf + u.field_data [joyent::UF_SCHEMA].off,
u.field_data [joyent::UF_SCHEMA].len);
}
if ((u.field_set & (1<<UF_HOST)) != 0)
if ((u.field_set & (1<<joyent::UF_HOST)) != 0)
{
host_ = String (
buf + u.field_data [UF_HOST].off,
u.field_data [UF_HOST].len);
buf + u.field_data [joyent::UF_HOST].off,
u.field_data [joyent::UF_HOST].len);
}
if ((u.field_set & (1<<UF_PORT)) != 0)
if ((u.field_set & (1<<joyent::UF_PORT)) != 0)
{
port_ = u.port;
port_string_ = String (
buf + u.field_data [UF_PORT].off,
u.field_data [UF_PORT].len);
buf + u.field_data [joyent::UF_PORT].off,
u.field_data [joyent::UF_PORT].len);
}
else
{
port_ = 0;
}
if ((u.field_set & (1<<UF_PATH)) != 0)
if ((u.field_set & (1<<joyent::UF_PATH)) != 0)
{
path_ = String (
buf + u.field_data [UF_PATH].off,
u.field_data [UF_PATH].len);
buf + u.field_data [joyent::UF_PATH].off,
u.field_data [joyent::UF_PATH].len);
}
if ((u.field_set & (1<<UF_QUERY)) != 0)
if ((u.field_set & (1<<joyent::UF_QUERY)) != 0)
{
query_ = String (
buf + u.field_data [UF_QUERY].off,
u.field_data [UF_QUERY].len);
buf + u.field_data [joyent::UF_QUERY].off,
u.field_data [joyent::UF_QUERY].len);
}
if ((u.field_set & (1<<UF_FRAGMENT)) != 0)
if ((u.field_set & (1<<joyent::UF_FRAGMENT)) != 0)
{
fragment_ = String (
buf + u.field_data [UF_FRAGMENT].off,
u.field_data [UF_FRAGMENT].len);
buf + u.field_data [joyent::UF_FRAGMENT].off,
u.field_data [joyent::UF_FRAGMENT].len);
}
if ((u.field_set & (1<<UF_USERINFO)) != 0)
if ((u.field_set & (1<<joyent::UF_USERINFO)) != 0)
{
userinfo_ = String (
buf + u.field_data [UF_USERINFO].off,
u.field_data [UF_USERINFO].len);
buf + u.field_data [joyent::UF_USERINFO].off,
u.field_data [joyent::UF_USERINFO].len);
}
m_url = URL (