diff options
| author | Joel Klinghed <the_jk@yahoo.com> | 2015-06-03 00:09:09 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@yahoo.com> | 2015-06-03 00:23:19 +0200 |
| commit | 41c45d4a4d6f8bea9b45d76ddef5d8bac71cfc5a (patch) | |
| tree | 70f5e4a20a7659529a48174a50ff24da92a01e44 /src/http.cc | |
| parent | 823dc403a9b56e00be4982d0082d30b8df5e53d6 (diff) | |
A start for an event handler
Diffstat (limited to 'src/http.cc')
| -rw-r--r-- | src/http.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/http.cc b/src/http.cc new file mode 100644 index 0000000..248bd6b --- /dev/null +++ b/src/http.cc @@ -0,0 +1,52 @@ +#include "common.hh" + +#include <iostream> + +#include "http.hh" + +namespace stuff { + +namespace { + +const std::string EOL = "\r\n"; + +const char* get_status_message(unsigned int status) { + switch (status) { + case 200: return "OK"; + case 201: return "Created"; + case 202: return "Accepted"; + case 203: return "Partial information"; + case 204: return "No response"; + case 301: return "Moved"; + case 302: return "Found"; + case 304: return "Not modified"; + case 400: return "Bad request"; + case 401: return "Unauthorized"; + case 402: return "Payment required"; + case 403: return "Forbidden"; + case 404: return "Not found"; + case 500: return "Internal error"; + case 501: return "Not implemented"; + } + return nullptr; +} + +} // namespace + +// static +void Http::response(unsigned int status, const std::string& content) { + if (status != 200) { + std::cout << "Status: " << status; + const char* msg = get_status_message(status); + if (msg) { + std::cout << ' ' << msg; + } + std::cout << EOL; + } + std::cout << "Content-Type: text/plain; charset=utf-8" << EOL; + std::cout << "Content-Length: " << content.size() << EOL; + std::cout << EOL; + std::cout << content; +} + +} // namespace stuff |
