construct RequestParser object on demand
pass CompressionType refs instead of ptrs to parser
This commit is contained in:
parent
d92e8ca8d2
commit
38251aa513
@ -69,10 +69,10 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
||||
CompressionType compression_type(noCompression);
|
||||
boost::tribool result;
|
||||
boost::tie(result, boost::tuples::ignore) =
|
||||
request_parser.Parse(request,
|
||||
RequestParser().Parse(request,
|
||||
incoming_data_buffer.data(),
|
||||
incoming_data_buffer.data() + bytes_transferred,
|
||||
&compression_type);
|
||||
compression_type);
|
||||
|
||||
// the request has been parsed
|
||||
if (result)
|
||||
|
@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef CONNECTION_H
|
||||
#define CONNECTION_H
|
||||
|
||||
#include "RequestParser.h"
|
||||
// #include "RequestParser.h"
|
||||
#include "Http/CompressionType.h"
|
||||
#include "Http/Request.h"
|
||||
|
||||
@ -96,7 +96,6 @@ class Connection : public std::enable_shared_from_this<Connection>
|
||||
RequestHandler &request_handler;
|
||||
boost::array<char, 8192> incoming_data_buffer;
|
||||
Request request;
|
||||
RequestParser request_parser;
|
||||
Reply reply;
|
||||
};
|
||||
|
||||
|
@ -37,7 +37,7 @@ RequestParser::RequestParser() : state_(method_start), header({"", ""}) {}
|
||||
void RequestParser::Reset() { state_ = method_start; }
|
||||
|
||||
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)
|
||||
{
|
||||
@ -52,7 +52,7 @@ RequestParser::Parse(Request &req, char *begin, char *end, http::CompressionType
|
||||
}
|
||||
|
||||
boost::tribool
|
||||
RequestParser::consume(Request &req, char input, http::CompressionType *compression_type)
|
||||
RequestParser::consume(Request &req, char input, http::CompressionType &compression_type)
|
||||
{
|
||||
switch (state_)
|
||||
{
|
||||
@ -178,11 +178,11 @@ RequestParser::consume(Request &req, char input, http::CompressionType *compress
|
||||
/* giving gzip precedence over deflate */
|
||||
if (header.value.find("deflate") != std::string::npos)
|
||||
{
|
||||
*compression_type = deflateRFC1951;
|
||||
compression_type = deflateRFC1951;
|
||||
}
|
||||
if (header.value.find("gzip") != std::string::npos)
|
||||
{
|
||||
*compression_type = gzipRFC1952;
|
||||
compression_type = gzipRFC1952;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,10 +46,10 @@ class RequestParser
|
||||
void Reset();
|
||||
|
||||
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:
|
||||
boost::tribool consume(Request &req, char input, CompressionType *compressionType);
|
||||
boost::tribool consume(Request &req, char input, CompressionType &compression_type);
|
||||
|
||||
inline bool isChar(int c);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user