Пример #1
0
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
	void operator()(served::response & response, const served::request & request)
	{
		(void) response;
		_story_obj.received.push_back(request.url().path());
		_story_obj.params = request.params;
	}
Пример #3
0
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#define CATCH_CONFIG_MAIN
#include "../test/catch.hpp"

#include <served/methods.hpp>
#include <served/request_parser_impl.hpp>

TEST_CASE("request parser impl can parse http requests", "[request_parser_impl]")
{
	served::request req;
	served::request_parser_impl parser(req);
	const char* request =
		"POST /you/got/served?reason=science#idet HTTP/1.1\r\n"
		"Host: api.datasift.com\r\n"
		"Content-Type: text/xml; charset=utf-8\r\n"
		"Content-Length: 15\r\n"
		"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);