Add Request and Response HTTP parsers

This commit is contained in:
Vinnie Falco
2013-10-03 20:28:16 -07:00
parent 44445ff1b8
commit b60a7f3363
10 changed files with 200 additions and 3 deletions

View File

@@ -189,7 +189,9 @@
<ClInclude Include="..\..\modules\beast_asio\http\HTTPParserImpl.h" />
<ClInclude Include="..\..\modules\beast_asio\http\HTTPParser.h" />
<ClInclude Include="..\..\modules\beast_asio\http\HTTPRequest.h" />
<ClInclude Include="..\..\modules\beast_asio\http\HTTPRequestParser.h" />
<ClInclude Include="..\..\modules\beast_asio\http\HTTPResponse.h" />
<ClInclude Include="..\..\modules\beast_asio\http\HTTPResponseParser.h" />
<ClInclude Include="..\..\modules\beast_asio\http\HTTPVersion.h" />
<ClInclude Include="..\..\modules\beast_asio\protocol\HandshakeDetectLogic.h" />
<ClInclude Include="..\..\modules\beast_asio\protocol\HandshakeDetectLogicPROXY.h" />
@@ -564,12 +566,24 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\beast_asio\http\HTTPRequestParser.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\beast_asio\http\HTTPResponse.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\beast_asio\http\HTTPResponseParser.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\beast_asio\http\HTTPVersion.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>

View File

@@ -1215,6 +1215,12 @@
<ClInclude Include="..\..\beast\net\BufferType.h">
<Filter>beast\net</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_asio\http\HTTPRequestParser.h">
<Filter>beast_asio\http</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_asio\http\HTTPResponseParser.h">
<Filter>beast_asio\http</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\modules\beast_core\containers\AbstractFifo.cpp">
@@ -1748,6 +1754,12 @@
<ClCompile Include="..\..\beast\net\impl\DynamicBuffer.cpp">
<Filter>beast\net\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\modules\beast_asio\http\HTTPRequestParser.cpp">
<Filter>beast_asio\http</Filter>
</ClCompile>
<ClCompile Include="..\..\modules\beast_asio\http\HTTPResponseParser.cpp">
<Filter>beast_asio\http</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="..\..\TODO.txt">

View File

@@ -61,3 +61,5 @@ namespace beast {
}
#include "http/HTTPParser.cpp"
#include "http/HTTPRequestParser.cpp"
#include "http/HTTPResponseParser.cpp"

View File

@@ -91,6 +91,8 @@ namespace beast {
}
# include "http/HTTPParser.h"
#include "http/HTTPRequestParser.h"
#include "http/HTTPResponseParser.h"
#include "http/HTTPClientType.h"

View File

@@ -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)
{

View File

@@ -77,7 +77,7 @@ public:
*/
SharedPtr <HTTPResponse> const& response ();
private:
protected:
Type m_type;
ScopedPointer <HTTPParserImpl> m_impl;
SharedPtr <HTTPRequest> m_request;

View File

@@ -0,0 +1,38 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
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 <HTTPRequest> const& HTTPRequestParser::request ()
{
return m_request;
}
}

View File

@@ -0,0 +1,46 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
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 <HTTPRequest> const& request ();
private:
//SharedPtr <HTTPRequest> m_request;
};
}
#endif

View File

@@ -0,0 +1,38 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
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 <HTTPResponse> const& HTTPResponseParser::response ()
{
return m_response;
}
}

View File

@@ -0,0 +1,46 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
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 <HTTPResponse> const& response ();
private:
//SharedPtr <HTTPResponse> m_response;
};
}
#endif