From b60a7f3363af61cdd0a4e5b330ec0572dd5f502d Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 3 Oct 2013 20:28:16 -0700 Subject: [PATCH] Add Request and Response HTTP parsers --- Builds/VisualStudio2012/beast.vcxproj | 14 ++++++ Builds/VisualStudio2012/beast.vcxproj.filters | 12 +++++ modules/beast_asio/beast_asio.cpp | 2 + modules/beast_asio/beast_asio.h | 2 + modules/beast_asio/http/HTTPClientType.cpp | 3 +- modules/beast_asio/http/HTTPParser.h | 2 +- modules/beast_asio/http/HTTPRequestParser.cpp | 38 +++++++++++++++ modules/beast_asio/http/HTTPRequestParser.h | 46 +++++++++++++++++++ .../beast_asio/http/HTTPResponseParser.cpp | 38 +++++++++++++++ modules/beast_asio/http/HTTPResponseParser.h | 46 +++++++++++++++++++ 10 files changed, 200 insertions(+), 3 deletions(-) create mode 100644 modules/beast_asio/http/HTTPRequestParser.cpp create mode 100644 modules/beast_asio/http/HTTPRequestParser.h create mode 100644 modules/beast_asio/http/HTTPResponseParser.cpp create mode 100644 modules/beast_asio/http/HTTPResponseParser.h diff --git a/Builds/VisualStudio2012/beast.vcxproj b/Builds/VisualStudio2012/beast.vcxproj index 15beb86587..64b48b8c7c 100644 --- a/Builds/VisualStudio2012/beast.vcxproj +++ b/Builds/VisualStudio2012/beast.vcxproj @@ -189,7 +189,9 @@ + + @@ -564,12 +566,24 @@ true true + + true + true + true + true + true true true true + + true + true + true + true + true true diff --git a/Builds/VisualStudio2012/beast.vcxproj.filters b/Builds/VisualStudio2012/beast.vcxproj.filters index 64a5a2197a..cdab9adef1 100644 --- a/Builds/VisualStudio2012/beast.vcxproj.filters +++ b/Builds/VisualStudio2012/beast.vcxproj.filters @@ -1215,6 +1215,12 @@ beast\net + + beast_asio\http + + + beast_asio\http + @@ -1748,6 +1754,12 @@ beast\net\impl + + beast_asio\http + + + beast_asio\http + diff --git a/modules/beast_asio/beast_asio.cpp b/modules/beast_asio/beast_asio.cpp index 3236c33aa1..e088b895bf 100644 --- a/modules/beast_asio/beast_asio.cpp +++ b/modules/beast_asio/beast_asio.cpp @@ -61,3 +61,5 @@ namespace beast { } #include "http/HTTPParser.cpp" +#include "http/HTTPRequestParser.cpp" +#include "http/HTTPResponseParser.cpp" diff --git a/modules/beast_asio/beast_asio.h b/modules/beast_asio/beast_asio.h index e00b609314..f66d966e22 100644 --- a/modules/beast_asio/beast_asio.h +++ b/modules/beast_asio/beast_asio.h @@ -91,6 +91,8 @@ namespace beast { } # include "http/HTTPParser.h" +#include "http/HTTPRequestParser.h" +#include "http/HTTPResponseParser.h" #include "http/HTTPClientType.h" diff --git a/modules/beast_asio/http/HTTPClientType.cpp b/modules/beast_asio/http/HTTPClientType.cpp index 582da6a271..aaee4052a1 100644 --- a/modules/beast_asio/http/HTTPClientType.cpp +++ b/modules/beast_asio/http/HTTPClientType.cpp @@ -178,7 +178,7 @@ public: URL m_url; boost::asio::ssl::context m_context; MemoryBlock m_buffer; - HTTPParser m_parser; + HTTPResponseParser m_parser; std::size_t m_messageLimitBytes; std::size_t m_bytesReceived; @@ -218,7 +218,6 @@ public: , m_url (url) , m_context (boost::asio::ssl::context::sslv23) , m_buffer (bufferSize) - , m_parser (HTTPParser::typeResponse) , m_messageLimitBytes (messageLimitBytes) , m_bytesReceived (0) { diff --git a/modules/beast_asio/http/HTTPParser.h b/modules/beast_asio/http/HTTPParser.h index 2788eea9de..4295310616 100644 --- a/modules/beast_asio/http/HTTPParser.h +++ b/modules/beast_asio/http/HTTPParser.h @@ -77,7 +77,7 @@ public: */ SharedPtr const& response (); -private: +protected: Type m_type; ScopedPointer m_impl; SharedPtr m_request; diff --git a/modules/beast_asio/http/HTTPRequestParser.cpp b/modules/beast_asio/http/HTTPRequestParser.cpp new file mode 100644 index 0000000000..0647bf5016 --- /dev/null +++ b/modules/beast_asio/http/HTTPRequestParser.cpp @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------------ +/* + 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 "HTTPRequestParser.h" + +namespace beast { + +HTTPRequestParser::HTTPRequestParser () + : HTTPParser (typeRequest) +{ +} + +HTTPRequestParser::~HTTPRequestParser () +{ +} + +SharedPtr const& HTTPRequestParser::request () +{ + return m_request; +} + +} diff --git a/modules/beast_asio/http/HTTPRequestParser.h b/modules/beast_asio/http/HTTPRequestParser.h new file mode 100644 index 0000000000..00cda4135f --- /dev/null +++ b/modules/beast_asio/http/HTTPRequestParser.h @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +/* + 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_REQUESTPARSER_H_INCLUDED +#define BEAST_HTTP_REQUESTPARSER_H_INCLUDED + +#include "HTTPParser.h" + +namespace beast { + +/** A parser for HTTPRequest objects. */ +class HTTPRequestParser : public HTTPParser +{ +public: + /** Construct a new parser for the specified HTTPMessage type. */ + HTTPRequestParser (); + + /** Destroy the parser. */ + ~HTTPRequestParser (); + + /** Return the HTTPRequest object produced from the parsing. */ + SharedPtr const& request (); + +private: + //SharedPtr m_request; +}; + +} + +#endif diff --git a/modules/beast_asio/http/HTTPResponseParser.cpp b/modules/beast_asio/http/HTTPResponseParser.cpp new file mode 100644 index 0000000000..b5e5857428 --- /dev/null +++ b/modules/beast_asio/http/HTTPResponseParser.cpp @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------------ +/* + 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 "HTTPResponseParser.h" + +namespace beast { + +HTTPResponseParser::HTTPResponseParser () + : HTTPParser (typeResponse) +{ +} + +HTTPResponseParser::~HTTPResponseParser () +{ +} + +SharedPtr const& HTTPResponseParser::response () +{ + return m_response; +} + +} diff --git a/modules/beast_asio/http/HTTPResponseParser.h b/modules/beast_asio/http/HTTPResponseParser.h new file mode 100644 index 0000000000..422c9f0b26 --- /dev/null +++ b/modules/beast_asio/http/HTTPResponseParser.h @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +/* + 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_RESPONSEPARSER_H_INCLUDED +#define BEAST_HTTP_RESPONSEPARSER_H_INCLUDED + +#include "HTTPParser.h" + +namespace beast { + +/** A parser for HTTPResponse objects. */ +class HTTPResponseParser : public HTTPParser +{ +public: + /** Construct a new parser for the specified HTTPMessage type. */ + HTTPResponseParser (); + + /** Destroy the parser. */ + ~HTTPResponseParser (); + + /** Return the HTTPResponse object produced from the parsing. */ + SharedPtr const& response (); + +private: + //SharedPtr m_response; +}; + +} + +#endif