diff options
Diffstat (limited to 'src/response.cpp')
-rw-r--r-- | src/response.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/response.cpp b/src/response.cpp index 96c1bc9..abe4363 100644 --- a/src/response.cpp +++ b/src/response.cpp @@ -1,19 +1,18 @@ -#include "response.h" -#include "misc_functions.h" #include <sstream> #include <boost/iostreams/filtering_streambuf.hpp> #include <boost/iostreams/copy.hpp> #include <boost/iostreams/filter/gzip.hpp> +#include "response.h" +#include "misc_functions.h" -std::string response(const std::string &body, bool gzip, bool html) { - const std::string head = response_head(gzip, html); +const std::string response(const std::string &body, client_opts_t &client_opts) { std::string out; bool processed = false; - if (html) { + if (client_opts.html) { out = "<html><head><meta name=\"robots\" content=\"noindex, nofollow\" /></head><body>" + body + "</body></html>"; processed = true; } - if (gzip) { + if (client_opts.gzip) { std::stringstream ss, zss; ss << body; boost::iostreams::filtering_streambuf<boost::iostreams::input> in; @@ -24,26 +23,29 @@ std::string response(const std::string &body, bool gzip, bool html) { processed = true; } if (processed) { - return head + out; + return response_head(out.length(), client_opts) + out; } - return head + body; + return response_head(body.length(), client_opts) + body; } -std::string response_head(bool gzip, bool html) { - const std::string content_type = html ? "text/html" : "text/plain"; +const std::string response_head(size_t content_length, client_opts_t &client_opts) { + const std::string content_type = client_opts.html ? "text/html" : "text/plain"; std::string head = "HTTP/1.1 200 OK\r\nServer: Ocelot 1.0"; head += "\r\nContent-Type: " + content_type; - if (gzip) { + if (client_opts.gzip) { head += "\r\nContent-Encoding: gzip"; } - head += "\r\nConnection: close\r\n\r\n"; + if (client_opts.http_close) { + head += "\r\nConnection: Close"; + } + head += "\r\nContent-Length: " + inttostr(content_length) + "\r\n\r\n"; return head; } -std::string error(const std::string &err) { - return response("d14:failure reason" + inttostr(err.length()) + ':' + err + "12:min intervali5400e8:intervali5400ee", false, false); +const std::string error(const std::string &err, client_opts_t &client_opts) { + return response("d14:failure reason" + inttostr(err.length()) + ':' + err + "12:min intervali5400e8:intervali5400ee", client_opts); } -std::string warning(const std::string &msg) { +const std::string warning(const std::string &msg) { return "15:warning message" + inttostr(msg.length()) + ':' + msg; } |