Files
xahaud/beast/http/tests/parser.test.cpp
Vinnie Falco 14b439ce43 Separate beast::http::body from beast::http::message (RIPD-660):
This changes the http::message object to no longer contain a body. It modifies
the parser to store the body in a separate object, or to pass the body data
to a functor. This allows the body to be stored in more flexible ways. For
example, in HTTP responses the body can be generated procedurally instead
of being required to exist entirely in memory at once.
2014-10-29 19:23:53 -07:00

99 lines
2.9 KiB
C++

//------------------------------------------------------------------------------
/*
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 <beast/http/message.h>
#include <beast/http/parser.h>
#include <beast/unit_test/suite.h>
#include <utility>
namespace beast {
namespace http {
class message_test : public beast::unit_test::suite
{
public:
std::pair <message, bool>
request (std::string const& text)
{
message m;
body b;
parser p (m, b, true);
auto result (p.write (boost::asio::buffer(text)));
p.write_eof();
return std::make_pair (std::move(m), result.first);
}
void
dump()
{
auto const result = request (
"GET / HTTP/1.1\r\n"
//"Connection: Upgrade\r\n"
//"Upgrade: Ripple\r\n"
"Field: \t Value \t \r\n"
"Blib: Continu\r\n"
" ation\r\n"
"Field: Hey\r\n"
"Content-Length: 1\r\n"
"\r\n"
"x"
);
log << result.first.headers;
log << "|" << result.first.headers["Field"] << "|";
}
void
run()
{
{
std::string const text =
"GET / HTTP/1.1\r\n"
"\r\n"
;
message m;
body b;
parser p (m, b, true);
auto result (p.write (boost::asio::buffer(text)));
expect (! result.first);
auto result2 (p.write_eof());
expect (! result2);
expect (p.complete());
}
{
// malformed
std::string const text =
"GET\r\n"
"\r\n"
;
message m;
body b;
parser p (m, b, true);
auto result = p.write (boost::asio::buffer(text));
if (expect (result.first))
expect (result.first.message() == "invalid HTTP method");
}
}
};
BEAST_DEFINE_TESTSUITE(message,http,beast);
} // http
} // beast