construct RequestParser object on demand

pass CompressionType refs instead of ptrs to parser
This commit is contained in:
Dennis Luxen 2014-12-17 15:48:33 +01:00
parent d92e8ca8d2
commit 38251aa513
4 changed files with 9 additions and 10 deletions

View File

@ -69,10 +69,10 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
CompressionType compression_type(noCompression); CompressionType compression_type(noCompression);
boost::tribool result; boost::tribool result;
boost::tie(result, boost::tuples::ignore) = boost::tie(result, boost::tuples::ignore) =
request_parser.Parse(request, RequestParser().Parse(request,
incoming_data_buffer.data(), incoming_data_buffer.data(),
incoming_data_buffer.data() + bytes_transferred, incoming_data_buffer.data() + bytes_transferred,
&compression_type); compression_type);
// the request has been parsed // the request has been parsed
if (result) if (result)

View File

@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef CONNECTION_H #ifndef CONNECTION_H
#define CONNECTION_H #define CONNECTION_H
#include "RequestParser.h" // #include "RequestParser.h"
#include "Http/CompressionType.h" #include "Http/CompressionType.h"
#include "Http/Request.h" #include "Http/Request.h"
@ -96,7 +96,6 @@ class Connection : public std::enable_shared_from_this<Connection>
RequestHandler &request_handler; RequestHandler &request_handler;
boost::array<char, 8192> incoming_data_buffer; boost::array<char, 8192> incoming_data_buffer;
Request request; Request request;
RequestParser request_parser;
Reply reply; Reply reply;
}; };

View File

@ -37,7 +37,7 @@ RequestParser::RequestParser() : state_(method_start), header({"", ""}) {}
void RequestParser::Reset() { state_ = method_start; } void RequestParser::Reset() { state_ = method_start; }
boost::tuple<boost::tribool, char *> boost::tuple<boost::tribool, char *>
RequestParser::Parse(Request &req, char *begin, char *end, http::CompressionType *compression_type) RequestParser::Parse(Request &req, char *begin, char *end, http::CompressionType &compression_type)
{ {
while (begin != end) while (begin != end)
{ {
@ -52,7 +52,7 @@ RequestParser::Parse(Request &req, char *begin, char *end, http::CompressionType
} }
boost::tribool boost::tribool
RequestParser::consume(Request &req, char input, http::CompressionType *compression_type) RequestParser::consume(Request &req, char input, http::CompressionType &compression_type)
{ {
switch (state_) switch (state_)
{ {
@ -178,11 +178,11 @@ RequestParser::consume(Request &req, char input, http::CompressionType *compress
/* giving gzip precedence over deflate */ /* giving gzip precedence over deflate */
if (header.value.find("deflate") != std::string::npos) if (header.value.find("deflate") != std::string::npos)
{ {
*compression_type = deflateRFC1951; compression_type = deflateRFC1951;
} }
if (header.value.find("gzip") != std::string::npos) if (header.value.find("gzip") != std::string::npos)
{ {
*compression_type = gzipRFC1952; compression_type = gzipRFC1952;
} }
} }

View File

@ -46,10 +46,10 @@ class RequestParser
void Reset(); void Reset();
boost::tuple<boost::tribool, char *> boost::tuple<boost::tribool, char *>
Parse(Request &req, char *begin, char *end, CompressionType *compressionType); Parse(Request &req, char *begin, char *end, CompressionType &compression_type);
private: private:
boost::tribool consume(Request &req, char input, CompressionType *compressionType); boost::tribool consume(Request &req, char input, CompressionType &compression_type);
inline bool isChar(int c); inline bool isChar(int c);