コード例 #1
0
ファイル: access_log.cpp プロジェクト: tj2013/served
void access_log(const served::response & res, const served::request & req)
{
	std::stringstream ss;

	boost::posix_time::time_facet *facet = new boost::posix_time::time_facet("%d/%b/%Y:%H:%M:%S");
	ss.imbue(std::locale(ss.getloc(), facet));

	std::string source = req.source();
	if ( source.empty() )
	{
		source = "-";
	}

	ss << source << " - - [" << boost::posix_time::second_clock::local_time() << " -0000]";
	ss << " \"" << method_to_string(req.method()) << " " << req.url().path() << " " << req.HTTP_version() << "\"";
	ss << " " << res.status() << " " << res.body_size();

	std::cout << ss.str() << std::endl;
}
コード例 #2
0
		"X-Example-Dup: val1\r\n"
		"X-Example-Dup: val2\r\n"
		"X-Example-Dup: val3\r\n"
		"\r\n"
		"you got served!";

	auto status = parser.parse(request, strlen(request));

	REQUIRE(status == served::request_parser_impl::FINISHED);

	SECTION("header is parsed correctly")
	{
		SECTION("check request")
		{
			REQUIRE(req.method()       == served::method::POST);
			REQUIRE(req.HTTP_version() == "HTTP/1.1");
			REQUIRE(req.body()         == "you got served!");
		}
		SECTION("check uri")
		{
			REQUIRE(req.url().URI()      == "/you/got/served?reason=science");
			REQUIRE(req.url().path()     == "/you/got/served");
			REQUIRE(req.url().query()    == "reason=science");
			REQUIRE(req.url().fragment() == "idet");
		}
		SECTION("check query")
		{
			REQUIRE(req.query["reason"] == "science");
		}
		SECTION("check fields")
		{