<commit_before>/**
 * request_reply.cpp
 *
 *  Created on: 28 авг. 2015 г.
 *      Author: zmij
 */

#include <tip/http/server/reply.hpp>
#include <tip/http/common/request.hpp>
#include <tip/http/common/response.hpp>

#include <tip/http/server/detail/context_registry.hpp>
#include <tip/http/server/locale_manager.hpp>

#include <tip/log.hpp>

#include <boost/iostreams/stream_buffer.hpp>
#include <boost/iostreams/device/back_inserter.hpp>
#include <boost/iostreams/device/array.hpp>
#include <set>

namespace tip {
namespace http {
namespace server {

struct reply::impl {
	typedef std::set< cookie, cookie_name_cmp > cookies_type;
	typedef boost::iostreams::stream_buffer<
			boost::iostreams::back_insert_device< body_type >> vector_buff_type;

	io_service_ptr		io_service_;

	request_const_ptr	req_;
	response_ptr		resp_;
	send_response_func 	send_response_;
	send_error_func		send_error_;

	bool				response_sent_;

	vector_buff_type	output_buffer_;
	std::ostream		output_stream_;
	cookies_type		cookies_;
	detail::context_registry registry_;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
	impl(io_service_ptr io_service, request_const_ptr req,
			send_response_func sr, send_error_func se) :
		io_service_(io_service), req_(req), resp_(new response{ {1,1} }),
		send_response_(sr), send_error_(se), response_sent_(false),
		output_buffer_(resp_->body_), output_stream_(&output_buffer_)
	{
	}
#pragma GCC diagnostic pop
	~impl()
	{
		if (!response_sent_ && send_error_) {
			send_error_(response_status::internal_server_error);
		}
	}

	void
	add_cookie(cookie&& c)
	{
		if (!response_sent_) {
			cookies_.insert(std::move(c));
		}
	}

	void
	add_cookie(cookie const& c)
	{
		add_cookie(std::move(cookie(c)));
	}

	void
	remove_cookie(std::string const& name)
	{
		using namespace boost::posix_time;
		using namespace boost::date_time;
		using boost::gregorian::date;<commit_msg>Fix for mac build<commit_after>/**
 * request_reply.cpp
 *
 *  Created on: 28 авг. 2015 г.
 *      Author: zmij
 */

#include <tip/http/server/reply.hpp>
#include <tip/http/common/request.hpp>
#include <tip/http/common/response.hpp>

#include <tip/http/server/detail/context_registry.hpp>
#include <tip/http/server/locale_manager.hpp>

#include <tip/log.hpp>

#include <boost/iostreams/stream_buffer.hpp>
#include <boost/iostreams/device/back_inserter.hpp>
#include <boost/iostreams/device/array.hpp>
#include <set>

namespace tip {
namespace http {
namespace server {

struct reply::impl {
	typedef std::set< cookie, cookie_name_cmp > cookies_type;
	typedef boost::iostreams::stream_buffer<
			boost::iostreams::back_insert_device< body_type >> vector_buff_type;

	io_service_ptr		io_service_;

	request_const_ptr	req_;
	response_ptr		resp_;
	send_response_func 	send_response_;
	send_error_func		send_error_;

	bool				response_sent_;

	vector_buff_type	output_buffer_;
	std::ostream		output_stream_;
	cookies_type		cookies_;
	detail::context_registry registry_;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
	impl(io_service_ptr io_service, request_const_ptr req,
			send_response_func sr, send_error_func se) :
		io_service_(io_service), req_(req), resp_(new response{ {1,1} }),
		send_response_(sr), send_error_(se), response_sent_(false),
		output_buffer_(resp_->body_), output_stream_(&output_buffer_)
	{
	}
#pragma GCC diagnostic pop
	~impl()
	{
		if (!response_sent_ && send_error_) {
			send_error_(response_status::internal_server_error);
		}
	}

	void
	add_cookie(cookie&& c)
	{
		if (!response_sent_) {
			cookies_.insert(std::move(c));
		}
	}

	void
	add_cookie(cookie const& c)
	{
		add_cookie(cookie(c));
	}

	void
	remove_cookie(std::string const& name)
	{
		using namespace boost::posix_time;
		using namespace boost::date_time;
		using boost::gregorian::date;
{'fraction_non_alphanumeric': 0.12042564235660524, 'fraction_numerical': 0.004152608357124318, 'mean_word_length': 5.510135135135135, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3687262', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1368, 'n_words': 256}