diff --git a/src/beast/Builds/VisualStudio2013/beast.vcxproj b/src/beast/Builds/VisualStudio2013/beast.vcxproj
index 6e32692d5..27af4aa52 100644
--- a/src/beast/Builds/VisualStudio2013/beast.vcxproj
+++ b/src/beast/Builds/VisualStudio2013/beast.vcxproj
@@ -159,9 +159,11 @@
+
-
+
+
@@ -549,7 +551,13 @@
true
-
+
+ true
+ true
+ true
+ true
+
+
true
true
true
diff --git a/src/beast/Builds/VisualStudio2013/beast.vcxproj.filters b/src/beast/Builds/VisualStudio2013/beast.vcxproj.filters
index dab2e43ca..5a20eee3c 100644
--- a/src/beast/Builds/VisualStudio2013/beast.vcxproj.filters
+++ b/src/beast/Builds/VisualStudio2013/beast.vcxproj.filters
@@ -1302,9 +1302,6 @@
beast\asio
-
- beast\http\impl
-
beast\container
@@ -1314,6 +1311,18 @@
beast\asio
+
+ beast\container
+
+
+ beast\http
+
+
+ beast\http\impl
+
+
+ beast\http
+
@@ -1715,9 +1724,6 @@
beast\http
-
- beast\http\impl
-
beast\strings\impl
@@ -1904,6 +1910,12 @@
beast\asio\tests
+
+ beast\http\impl
+
+
+ beast\http\impl
+
diff --git a/src/beast/beast/asio/Asio.cpp b/src/beast/beast/asio/Asio.cpp
index d578299ff..a187814b8 100644
--- a/src/beast/beast/asio/Asio.cpp
+++ b/src/beast/beast/asio/Asio.cpp
@@ -27,3 +27,4 @@
#include "tests/shared_handler_tests.cpp"
#include "abstract_socket.cpp" // TEMPORARY!
+
diff --git a/src/beast/beast/asio/memory_buffer.h b/src/beast/beast/asio/memory_buffer.h
index e77d1d420..91e2029a6 100644
--- a/src/beast/beast/asio/memory_buffer.h
+++ b/src/beast/beast/asio/memory_buffer.h
@@ -25,6 +25,7 @@
#include
#include
+#include
#include
namespace beast {
@@ -38,8 +39,9 @@ class memory_buffer
: private empty_base_optimization
{
private:
- static_assert (std::is_trivially_constructible ::value,
- "T must be trivially constructible");
+ static_assert (std::is_same ::value ||
+ std::is_same ::value,
+ "memory_buffer only works with char and unsigned char");
typedef empty_base_optimization Base;
diff --git a/src/beast/beast/http/HTTP.cpp b/src/beast/beast/http/HTTP.cpp
index a4913b038..7d99836cf 100644
--- a/src/beast/beast/http/HTTP.cpp
+++ b/src/beast/beast/http/HTTP.cpp
@@ -21,4 +21,5 @@
#include "impl/URL.cpp"
#include "impl/ParsedURL.cpp"
-#include "impl/http_parser.cpp"
+#include "impl/joyent_parser.cpp"
+#include "impl/raw_parser.cpp"
diff --git a/src/beast/beast/http/impl/http_parser.cpp b/src/beast/beast/http/basic_message.h
similarity index 57%
rename from src/beast/beast/http/impl/http_parser.cpp
rename to src/beast/beast/http/basic_message.h
index cfc751b87..b459f0a41 100644
--- a/src/beast/beast/http/impl/http_parser.cpp
+++ b/src/beast/beast/http/basic_message.h
@@ -17,20 +17,70 @@
*/
//==============================================================================
-#include "BeastConfig.h"
+#ifndef BEAST_ASIO_HTTP_BASIC_MESSAGE_H_INCLUDED
+#define BEAST_ASIO_HTTP_BASIC_MESSAGE_H_INCLUDED
-#include "../../Config.h"
+#include
namespace beast {
+namespace http {
-#ifdef _MSC_VER
-# pragma warning (push)
-# pragma warning (disable: 4127) // conditional expression is constant
-# pragma warning (disable: 4244) // integer conversion, possible loss of data
-#endif
-#include "http-parser/http_parser.c"
-#ifdef _MSC_VER
-# pragma warning (pop)
-#endif
+namespace method {
+enum methodc_t
+{
+ http_delete,
+ http_get,
+ http_head,
+ http_post,
+ http_put,
+
+ // pathological
+ http_connect,
+ http_options,
+ http_trace,
+
+ // webdav
+ http_copy,
+ http_lock,
+ http_mkcol,
+ http_move,
+ http_propfind,
+ http_proppatch,
+ http_search,
+ http_unlock,
+
+ // subversion
+ http_report,
+ http_mkactivity,
+ http_checkout,
+ http_merge,
+
+ // upnp
+ http_msearch,
+ http_notify,
+ http_subscribe,
+ http_unsubscribe,
+
+ // RFC-5789
+ http_patch,
+ http_purge
+};
+} // method
+
+class basic_message
+{
+private:
+
+public:
+};
+
+class basic_request
+{
+public:
+
+};
}
+}
+
+#endif
diff --git a/src/beast/beast/http/impl/ParsedURL.cpp b/src/beast/beast/http/impl/ParsedURL.cpp
index ee103d779..d1b97dd1e 100644
--- a/src/beast/beast/http/impl/ParsedURL.cpp
+++ b/src/beast/beast/http/impl/ParsedURL.cpp
@@ -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<
+
+ Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+//==============================================================================
+
+#include "BeastConfig.h"
+
+#include "../../Config.h"
+
+namespace beast {
+namespace joyent {
+
+#ifdef _MSC_VER
+# pragma warning (push)
+# pragma warning (disable: 4127) // conditional expression is constant
+# pragma warning (disable: 4244) // integer conversion, possible loss of data
+#endif
+#include "http-parser/http_parser.c"
+#ifdef _MSC_VER
+# pragma warning (pop)
+#endif
+
+}
+}
+
+namespace boost {
+namespace system {
+
+template <>
+struct is_error_code_enum
+ : std::true_type
+{
+};
+
+template <>
+struct is_error_condition_enum
+ : std::true_type
+{
+};
+
+}
+}
+
+namespace beast {
+namespace joyent {
+
+http::method::methodc_t
+convert_http_method (joyent::http_method m)
+{
+ switch (m)
+ {
+ case HTTP_DELETE: return http::method::http_delete;
+ case HTTP_GET: return http::method::http_get;
+ case HTTP_HEAD: return http::method::http_head;
+ case HTTP_POST: return http::method::http_post;
+ case HTTP_PUT: return http::method::http_put;
+
+ // pathological
+ case HTTP_CONNECT: return http::method::http_connect;
+ case HTTP_OPTIONS: return http::method::http_options;
+ case HTTP_TRACE: return http::method::http_trace;
+
+ // webdav
+ case HTTP_COPY: return http::method::http_copy;
+ case HTTP_LOCK: return http::method::http_lock;
+ case HTTP_MKCOL: return http::method::http_mkcol;
+ case HTTP_MOVE: return http::method::http_move;
+ case HTTP_PROPFIND: return http::method::http_propfind;
+ case HTTP_PROPPATCH: return http::method::http_proppatch;
+ case HTTP_SEARCH: return http::method::http_search;
+ case HTTP_UNLOCK: return http::method::http_unlock;
+
+ // subversion
+ case HTTP_REPORT: return http::method::http_report;
+ case HTTP_MKACTIVITY: return http::method::http_mkactivity;
+ case HTTP_CHECKOUT: return http::method::http_checkout;
+ case HTTP_MERGE: return http::method::http_merge;
+
+ // upnp
+ case HTTP_MSEARCH: return http::method::http_msearch;
+ case HTTP_NOTIFY: return http::method::http_notify;
+ case HTTP_SUBSCRIBE: return http::method::http_subscribe;
+ case HTTP_UNSUBSCRIBE: return http::method::http_unsubscribe;
+
+ // RFC-5789
+ case HTTP_PATCH: return http::method::http_patch;
+ case HTTP_PURGE: return http::method::http_purge;
+ };
+
+ return http::method::http_get;
+}
+
+boost::system::error_code
+convert_http_errno (joyent::http_errno err)
+{
+ class http_error_category_t
+ : public boost::system::error_category
+ {
+ private:
+ typedef boost::system::error_code error_code;
+ typedef boost::system::error_condition error_condition;
+
+ public:
+ char const*
+ name() const noexcept override
+ {
+ return "http_errno";
+ }
+
+ std::string
+ message (int ev) const override
+ {
+ return joyent::http_errno_name (
+ joyent::http_errno (ev));
+ }
+
+ error_condition
+ default_error_condition (int ev) const noexcept override
+ {
+ return error_condition (ev, *this);
+ }
+
+ bool
+ equivalent (int code, error_condition const& condition
+ ) const noexcept override
+ {
+ return default_error_condition (code) == condition;
+ }
+
+ bool
+ equivalent (error_code const& code, int condition
+ ) const noexcept override
+ {
+ return *this == code.category() &&
+ code.value() == condition;
+ }
+ };
+
+ static http_error_category_t http_error_category;
+
+ return boost::system::error_code (
+ err, http_error_category);
+}
+
+}
+}
diff --git a/src/beast/beast/http/impl/http_parser.h b/src/beast/beast/http/impl/joyent_parser.h
similarity index 73%
rename from src/beast/beast/http/impl/http_parser.h
rename to src/beast/beast/http/impl/joyent_parser.h
index 9b0fb1968..01b307e29 100644
--- a/src/beast/beast/http/impl/http_parser.h
+++ b/src/beast/beast/http/impl/joyent_parser.h
@@ -17,17 +17,30 @@
*/
//==============================================================================
-#ifndef BEAST_HTTP_HTTP_PARSER_H_INCLUDED
-#define BEAST_HTTP_HTTP_PARSER_H_INCLUDED
+#ifndef BEAST_HTTP_JOYENT_PARSER_H_INCLUDED
+#define BEAST_HTTP_JOYENT_PARSER_H_INCLUDED
#include "BeastConfig.h"
-// Wraps the C-language joyent http parser header in our namespace
+#include "../basic_message.h"
+
+// TODO Use
+#include
+
+// Wraps the C-language joyent http parser header in a namespace
namespace beast {
+namespace joyent {
#include "http-parser/http_parser.h"
+http::method::methodc_t
+convert_http_method (joyent::http_method m);
+
+boost::system::error_code
+convert_http_errno (joyent::http_errno err);
+
+}
}
#endif
diff --git a/src/beast/beast/http/impl/raw_parser.cpp b/src/beast/beast/http/impl/raw_parser.cpp
new file mode 100644
index 000000000..b87fd520c
--- /dev/null
+++ b/src/beast/beast/http/impl/raw_parser.cpp
@@ -0,0 +1,293 @@
+//------------------------------------------------------------------------------
+/*
+ This file is part of Beast: https://github.com/vinniefalco/Beast
+ Copyright 2013, Vinnie Falco
+
+ Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+//==============================================================================
+
+#include "../raw_parser.h"
+
+#include "joyent_parser.h"
+
+#include
+
+namespace beast {
+namespace http {
+
+raw_parser::raw_parser (callback& cb)
+ : m_cb (cb)
+{
+ static_assert (sizeof(joyent::http_parser) == sizeof(state_t),
+ "state_t size must match http_parser size");
+
+ static_assert (sizeof(joyent::http_parser_settings) == sizeof(hooks_t),
+ "hooks_t size must match http_parser_settings size");
+
+ auto s (reinterpret_cast (&m_state));
+ s->data = this;
+
+ auto h (reinterpret_cast (&m_hooks));
+ h->on_message_begin = &raw_parser::on_message_start;
+ h->on_url = &raw_parser::on_url;
+ h->on_status = &raw_parser::on_status;
+ h->on_header_field = &raw_parser::on_header_field;
+ h->on_header_value = &raw_parser::on_header_value;
+ h->on_headers_complete = &raw_parser::on_headers_done;
+ h->on_body = &raw_parser::on_body;
+ h->on_message_complete = &raw_parser::on_message_complete;
+}
+
+raw_parser::~raw_parser()
+{
+}
+
+void
+raw_parser::reset (message_type type)
+{
+ auto s (reinterpret_cast (&m_state));
+ http_parser_init (s, (type == request)
+ ? joyent::HTTP_REQUEST : joyent::HTTP_RESPONSE);
+}
+
+auto
+raw_parser::process_data (void const* buf, std::size_t bytes) ->
+ std::pair
+{
+ auto s (reinterpret_cast (&m_state));
+ auto h (reinterpret_cast (&m_hooks));
+ std::size_t const bytes_used (joyent::http_parser_execute (s, h,
+ static_cast (buf), bytes));
+ return std::make_pair (m_ec, bytes_used);;
+}
+
+auto
+raw_parser::process_eof () ->
+ error_code
+{
+ auto s (reinterpret_cast (&m_state));
+ auto h (reinterpret_cast (&m_hooks));
+ joyent::http_parser_execute (s, h, nullptr, 0);
+ return m_ec;
+}
+
+//------------------------------------------------------------------------------
+
+int
+raw_parser::do_message_start ()
+{
+ auto const p (reinterpret_cast (&m_state));
+ if (p->type == joyent::HTTP_REQUEST)
+ m_ec = m_cb.get().on_request ();
+ else if (p->type == joyent::HTTP_RESPONSE)
+ m_ec = m_cb.get().on_response ();
+ return m_ec ? 1 : 0;
+}
+
+int
+raw_parser::do_url (char const* in, std::size_t bytes)
+{
+ m_ec = m_cb.get().on_url (in, bytes);
+ return m_ec ? 1 : 0;
+}
+
+int
+raw_parser::do_status (char const* in, std::size_t bytes)
+{
+ auto const p (reinterpret_cast (&m_state));
+ m_ec = m_cb.get().on_status (p->status_code, in, bytes);
+ return m_ec ? 1 : 0;
+}
+
+int
+raw_parser::do_header_field (char const* in, std::size_t bytes)
+{
+ m_ec = m_cb.get().on_header_field (in, bytes);
+ return m_ec ? 1 : 0;
+}
+
+int
+raw_parser::do_header_value (char const* in, std::size_t bytes)
+{
+ m_ec = m_cb.get().on_header_value (in, bytes);
+ return m_ec ? 1 : 0;
+}
+
+int
+raw_parser::do_headers_done ()
+{
+ auto const p (reinterpret_cast (&m_state));
+ bool const keep_alive (joyent::http_should_keep_alive (p) != 0);
+ error_code const ec (
+ m_cb.get().on_headers_done (keep_alive));
+ return m_ec ? 1 : 0;
+}
+
+int
+raw_parser::do_body (char const* in, std::size_t bytes)
+{
+ auto const p (reinterpret_cast (&m_state));
+ bool const is_final (
+ joyent::http_body_is_final (p) != 0);
+ m_ec = m_cb.get().on_body (is_final, in, bytes);
+ return m_ec ? 1 : 0;
+}
+
+int
+raw_parser::do_message_complete ()
+{
+ auto const p (reinterpret_cast (&m_state));
+ bool const keep_alive (joyent::http_should_keep_alive (p) != 0);
+ error_code const ec (m_cb.get().on_message_complete (keep_alive));
+ return m_ec ? 1 : 0;
+}
+
+//------------------------------------------------------------------------------
+
+int
+raw_parser::on_message_start (joyent::http_parser* p)
+{
+ return reinterpret_cast (
+ p->data)->do_message_start();
+}
+
+int
+raw_parser::on_url (joyent::http_parser* p,
+ char const* in, std::size_t bytes)
+{
+ return reinterpret_cast (
+ p->data)->do_url (in, bytes);
+}
+
+int
+raw_parser::on_status (joyent::http_parser* p,
+ char const* in, std::size_t bytes)
+{
+ return reinterpret_cast (
+ p->data)->do_status (in, bytes);
+}
+
+int
+raw_parser::on_header_field (joyent::http_parser* p,
+ char const* in, std::size_t bytes)
+{
+ return reinterpret_cast (
+ p->data)->do_header_field (in, bytes);
+}
+
+int
+raw_parser::on_header_value (joyent::http_parser* p,
+ char const* in, std::size_t bytes)
+{
+ return reinterpret_cast (
+ p->data)->do_header_value (in, bytes);
+}
+
+int
+raw_parser::on_headers_done (joyent::http_parser* p)
+{
+ return reinterpret_cast (
+ p->data)->do_headers_done();
+}
+
+int
+raw_parser::on_body (joyent::http_parser* p,
+ char const* in, std::size_t bytes)
+{
+ return reinterpret_cast (
+ p->data)->do_body (
+ in, bytes);
+}
+
+int
+raw_parser::on_message_complete (joyent::http_parser* p)
+{
+ return reinterpret_cast (
+ p->data)->do_message_complete();
+}
+
+//------------------------------------------------------------------------------
+
+auto
+raw_parser::callback::on_request () ->
+ error_code
+{
+ return error_code();
+}
+
+auto
+raw_parser::callback::on_response () ->
+ error_code
+{
+ return error_code();
+}
+
+auto
+raw_parser::callback::on_url(
+ void const*, std::size_t) ->
+ error_code
+{
+ return error_code();
+}
+
+auto
+raw_parser::callback::on_status (int,
+ void const*, std::size_t) ->
+ error_code
+{
+ return error_code();
+}
+
+auto
+raw_parser::callback::on_header_field (
+ void const*, std::size_t) ->
+ error_code
+{
+ return error_code();
+}
+
+auto
+raw_parser::callback::on_header_value (
+ void const*, std::size_t) ->
+ error_code
+{
+ return error_code();
+}
+
+auto
+raw_parser::callback::on_headers_done (
+ bool) ->
+ error_code
+{
+ return error_code();
+}
+
+auto
+raw_parser::callback::on_body (
+ bool, void const*, std::size_t) ->
+ error_code
+{
+ return error_code();
+}
+
+auto
+raw_parser::callback::on_message_complete (
+ bool) ->
+ error_code
+{
+ return error_code();
+}
+
+}
+}
diff --git a/src/beast/beast/http/raw_parser.h b/src/beast/beast/http/raw_parser.h
new file mode 100644
index 000000000..69c4dfda6
--- /dev/null
+++ b/src/beast/beast/http/raw_parser.h
@@ -0,0 +1,202 @@
+//------------------------------------------------------------------------------
+/*
+ This file is part of Beast: https://github.com/vinniefalco/Beast
+ Copyright 2013, Vinnie Falco
+
+ Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+//==============================================================================
+
+#ifndef BEAST_HTTP_RAW_PARSER_H_INCLUDED
+#define BEAST_HTTP_RAW_PARSER_H_INCLUDED
+
+#include "../utility/empty_base_optimization.h"
+
+#include // change to soon
+
+#include
+#include
+#include
+
+namespace beast {
+
+namespace joyent {
+struct http_parser;
+};
+
+namespace http {
+
+/** Raw HTTP message parser.
+ This is implemented using a zero-allocation state machine. The caller
+ is responsible for all buffer management.
+*/
+class raw_parser
+{
+private:
+ typedef boost::system::error_code error_code;
+
+public:
+ enum message_type
+ {
+ request,
+ response
+ };
+
+ struct callback
+ {
+ /** Called when the first byte of an HTTP request is received. */
+ virtual
+ error_code
+ on_request ();
+
+ /** Called when the first byte of an HTTP response is received. */
+ virtual
+ error_code
+ on_response ();
+
+ /** Called repeatedly to provide parts of the URL.
+ This is only for requests.
+ */
+ virtual
+ error_code
+ on_url (
+ void const* in, std::size_t bytes);
+
+ /** Called when the status is received.
+ This is only for responses.
+ */
+ virtual
+ error_code
+ on_status (int status_code,
+ void const* in, std::size_t bytes);
+
+ /** Called repeatedly to provide parts of a field. */
+ virtual
+ error_code
+ on_header_field (
+ void const* in, std::size_t bytes);
+
+ /** Called repeatedly to provide parts of a value. */
+ virtual
+ error_code
+ on_header_value (
+ void const* in, std::size_t bytes);
+
+ /** Called when there are no more bytes of headers remaining. */
+ virtual
+ error_code
+ on_headers_done (
+ bool keep_alive);
+
+ /** Called repeatedly to provide parts of the body. */
+ virtual
+ error_code
+ on_body (bool is_final,
+ void const* in, std::size_t bytes);
+
+ /** Called when there are no more bytes of body remaining. */
+ virtual
+ error_code on_message_complete (
+ bool keep_alive);
+ };
+
+ explicit raw_parser (callback& cb);
+
+ ~raw_parser();
+
+ /** Prepare to parse a new message.
+ The previous state information, if any, is discarded.
+ */
+ void
+ reset (message_type type);
+
+ /** Processs message data.
+ The return value includes the error code if any,
+ and the number of bytes consumed in the input sequence.
+ */
+ std::pair
+ process_data (void const* in, std::size_t bytes);
+
+ /** Notify the parser the end of the data is reached.
+ Normally this will be called in response to the remote
+ end closing down its half of the connection.
+ */
+ error_code
+ process_eof ();
+
+private:
+ int do_message_start ();
+ int do_url (char const* in, std::size_t bytes);
+ int do_status (char const* in, std::size_t bytes);
+ int do_header_field (char const* in, std::size_t bytes);
+ int do_header_value (char const* in, std::size_t bytes);
+ int do_headers_done ();
+ int do_body (char const* in, std::size_t bytes);
+ int do_message_complete ();
+
+ static int on_message_start (joyent::http_parser*);
+ static int on_url (joyent::http_parser*, char const*, std::size_t);
+ static int on_status (joyent::http_parser*, char const*, std::size_t);
+ static int on_header_field (joyent::http_parser*, char const*, std::size_t);
+ static int on_header_value (joyent::http_parser*, char const*, std::size_t);
+ static int on_headers_done (joyent::http_parser*);
+ static int on_body (joyent::http_parser*, char const*, std::size_t);
+ static int on_message_complete (joyent::http_parser*);
+
+ // These structures must exactly match the
+ // declarations in joyent http_parser.h include
+ //
+ struct state_t
+ {
+ unsigned int type : 2;
+ unsigned int flags : 6;
+ unsigned int state : 8;
+ unsigned int header_state : 8;
+ unsigned int index : 8;
+ std::uint32_t nread;
+ std::uint64_t content_length;
+ unsigned short http_major;
+ unsigned short http_minor;
+ unsigned int status_code : 16;
+ unsigned int method : 8;
+ unsigned int http_errno : 7;
+ unsigned int upgrade : 1;
+ void *data;
+ };
+
+ typedef int (*data_cb_t) (
+ state_t*, const char *at, size_t length);
+ typedef int (*cb_t) (state_t*);
+
+ struct hooks_t
+ {
+ cb_t on_message_begin;
+ data_cb_t on_url;
+ data_cb_t on_status;
+ data_cb_t on_header_field;
+ data_cb_t on_header_value;
+ cb_t on_headers_complete;
+ data_cb_t on_body;
+ cb_t on_message_complete;
+ };
+
+ std::reference_wrapper m_cb;
+ error_code m_ec;
+ char m_state [sizeof(state_t)];
+ char m_hooks [sizeof(hooks_t)];
+};
+
+}
+}
+
+#endif
diff --git a/src/beast/modules/beast_asio/beast_asio.cpp b/src/beast/modules/beast_asio/beast_asio.cpp
index a9626e78b..f47f90c30 100644
--- a/src/beast/modules/beast_asio/beast_asio.cpp
+++ b/src/beast/modules/beast_asio/beast_asio.cpp
@@ -23,7 +23,7 @@
#include "beast_asio.h"
-# include "../../beast/http/impl/http_parser.h"
+# include "../../beast/http/impl/joyent_parser.h"
#include "basics/PeerRole.cpp"
#include "basics/SSLContext.cpp"
diff --git a/src/beast/modules/beast_asio/http/HTTPParser.cpp b/src/beast/modules/beast_asio/http/HTTPParser.cpp
index db11fda65..ae861e5b9 100644
--- a/src/beast/modules/beast_asio/http/HTTPParser.cpp
+++ b/src/beast/modules/beast_asio/http/HTTPParser.cpp
@@ -22,7 +22,7 @@ namespace beast {
HTTPParser::HTTPParser (Type type)
: m_type (type)
, m_impl (new HTTPParserImpl (
- (type == typeResponse) ? HTTP_RESPONSE : HTTP_REQUEST))
+ (type == typeResponse) ? joyent::HTTP_RESPONSE : joyent::HTTP_REQUEST))
{
}
diff --git a/src/beast/modules/beast_asio/http/HTTPParserImpl.h b/src/beast/modules/beast_asio/http/HTTPParserImpl.h
index ccb4f0fff..189d56890 100644
--- a/src/beast/modules/beast_asio/http/HTTPParserImpl.h
+++ b/src/beast/modules/beast_asio/http/HTTPParserImpl.h
@@ -30,7 +30,7 @@ public:
stringReservation = 256
};
- explicit HTTPParserImpl (enum http_parser_type type)
+ explicit HTTPParserImpl (enum joyent::http_parser_type type)
: m_finished (false)
, m_was_value (false)
, m_headersComplete (false)
@@ -47,7 +47,7 @@ public:
m_field.reserve (stringReservation);
m_value.reserve (stringReservation);
- http_parser_init (&m_parser, type);
+ joyent::http_parser_init (&m_parser, type);
m_parser.data = this;
}
@@ -62,19 +62,19 @@ public:
String message () const
{
- return String (http_errno_name (static_cast <
- enum http_errno> (m_parser.http_errno)));
+ return String (joyent::http_errno_name (static_cast <
+ enum joyent::http_errno> (m_parser.http_errno)));
}
std::size_t process (void const* buf, std::size_t bytes)
{
- return http_parser_execute (&m_parser,
+ return joyent::http_parser_execute (&m_parser,
&m_settings, static_cast (buf), bytes);
}
void process_eof ()
{
- http_parser_execute (&m_parser, &m_settings, nullptr, 0);
+ joyent::http_parser_execute (&m_parser, &m_settings, nullptr, 0);
}
bool finished () const
@@ -107,8 +107,8 @@ public:
String http_errno_message () const
{
- return String (http_errno_name (
- static_cast (
+ return String (joyent::http_errno_name (
+ static_cast (
m_parser.http_errno)));
}
@@ -204,53 +204,53 @@ private:
}
private:
- static int on_message_begin (http_parser* parser)
+ static int on_message_begin (joyent::http_parser* parser)
{
return static_cast (parser->data)->
onMessageBegin ();
}
- static int on_url (http_parser* parser, const char *at, size_t length)
+ static int on_url (joyent::http_parser* parser, const char *at, size_t length)
{
return static_cast (parser->data)->
onUrl (at, length);
}
- static int on_status (http_parser* parser,
+ static int on_status (joyent::http_parser* parser,
char const* /*at*/, size_t /*length*/)
{
return static_cast (parser->data)->
onStatus ();
}
- static int on_header_field (http_parser* parser,
+ static int on_header_field (joyent::http_parser* parser,
const char *at, size_t length)
{
return static_cast (parser->data)->
onHeaderField (at, length);
}
- static int on_header_value (http_parser* parser,
+ static int on_header_value (joyent::http_parser* parser,
const char *at, size_t length)
{
return static_cast (parser->data)->
onHeaderValue (at, length);
}
- static int on_headers_complete (http_parser* parser)
+ static int on_headers_complete (joyent::http_parser* parser)
{
return static_cast (parser->data)->
onHeadersComplete ();
}
- static int on_body (http_parser* parser,
+ static int on_body (joyent::http_parser* parser,
const char *at, size_t length)
{
return static_cast (parser->data)->
onBody (at, length);
}
- static int on_message_complete (http_parser* parser)
+ static int on_message_complete (joyent::http_parser* parser)
{
return static_cast (parser->data)->
onMessageComplete ();
@@ -258,8 +258,8 @@ private:
private:
bool m_finished;
- http_parser_settings m_settings;
- http_parser m_parser;
+ joyent::http_parser_settings m_settings;
+ joyent::http_parser m_parser;
StringPairArray m_fields;
bool m_was_value;
std::string m_field;