aboutsummaryrefslogblamecommitdiffstats
path: root/http_response.h
blob: eff1d0f101c1102aff820645d17d56950765ce19 (plain) (tree)
1
2
3
4
5
6
7
8
9


                        
                 
 
              
 

                   
                         
                                
                      
                                                             
 
                     
                                                   
                                                             
                                                                                  
                                                                                  
                                                                                   
 



                                 
 







                                                 














                                               

      
#pragma once
#include <string>
#include <unordered_map>
#include "json.h"

namespace crow
{
    struct response
    {
        std::string body;
        json::wvalue json_value;
        int code{200};
        std::unordered_map<std::string, std::string> headers;

        response() {}
        explicit response(int code) : code(code) {}
        response(std::string body) : body(std::move(body)) {}
        response(json::wvalue&& json_value) : json_value(std::move(json_value)) {}
        response(const json::wvalue& json_value) : body(json::dump(json_value)) {}
        response(int code, std::string body) : body(std::move(body)), code(code) {}

        response(response&& r)
        {
            *this = std::move(r);
        }

        response& operator = (response&& r)
        {
            body = std::move(r.body);
            json_value = std::move(r.json_value);
            code = r.code;
            headers = std::move(r.headers);
            return *this;
        }

        void send(const std::string& body_part)
        {
            body += body_part;
        }

        void end()
        {
        }

        void end(const std::string& body_part)
        {
            body += body_part;
            end();
        }
    };
}