<commit_before>#ifndef SERVER_HTTP_HPP
#define	SERVER_HTTP_HPP

#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>

#include <regex>
#include <unordered_map>
#include <thread>
#include <functional>
#include <iostream>

namespace SimpleWeb {
    template <class socket_type>
    class ServerBase {
    public:
        class Response {
            friend class ServerBase<socket_type>;
        private:
            std::shared_ptr<boost::asio::strand> strand;
            
            boost::asio::yield_context& yield;
            
            boost::asio::streambuf streambuf;

            std::shared_ptr<socket_type> socket;
            
            Response(boost::asio::io_service& io_service, std::shared_ptr<socket_type> socket, std::shared_ptr<boost::asio::strand> strand, 
                    boost::asio::yield_context& yield): strand(strand), yield(yield), socket(socket), stream(&streambuf) {}
            
            void flush() {
                boost::asio::streambuf write_buffer;
                std::ostream response(&write_buffer);
                response << stream.rdbuf();

                boost::system::error_code ec;
                boost::asio::async_write(*socket, write_buffer, yield[ec]);<commit_msg>Fixes #14. Now does not copy pointers in the stream to be sent to client.<commit_after>#ifndef SERVER_HTTP_HPP
#define	SERVER_HTTP_HPP

#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>

#include <regex>
#include <unordered_map>
#include <thread>
#include <functional>
#include <iostream>

namespace SimpleWeb {
    template <class socket_type>
    class ServerBase {
    public:
        class Response {
            friend class ServerBase<socket_type>;
        private:
            std::shared_ptr<boost::asio::strand> strand;
            
            boost::asio::yield_context& yield;
            
            boost::asio::streambuf streambuf;

            std::shared_ptr<socket_type> socket;
            
            Response(boost::asio::io_service& io_service, std::shared_ptr<socket_type> socket, std::shared_ptr<boost::asio::strand> strand, 
                    boost::asio::yield_context& yield): strand(strand), yield(yield), socket(socket), stream(&streambuf) {}
            
            void flush() {
                boost::system::error_code ec;
                boost::asio::async_write(*socket, streambuf, yield[ec]);
{'fraction_non_alphanumeric': 0.11601513240857503, 'fraction_numerical': 0.0008406893652795292, 'mean_word_length': 2.6503067484662575, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 29, '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': '604655', 'n_tokens_mistral': 706, 'n_tokens_neox': 655, 'n_words': 137}