summaryrefslogtreecommitdiff
path: root/includes/HttpServer.h
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2012-02-28 04:57:59 +0100
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2012-02-28 04:57:59 +0100
commit30c37eb549c17b29a8131598cc06aeaf374896f5 (patch)
tree0105edcf5c8643c83a73f205577061686283a18e /includes/HttpServer.h
parent3998f46d06ec5235ade776ec8615e081dd909920 (diff)
Having a slightly better approach for writing Http responses.
Diffstat (limited to 'includes/HttpServer.h')
-rw-r--r--includes/HttpServer.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/includes/HttpServer.h b/includes/HttpServer.h
index 37353ac..7dbf912 100644
--- a/includes/HttpServer.h
+++ b/includes/HttpServer.h
@@ -9,6 +9,7 @@
#include <Exceptions.h>
#include <Threads.h>
#include <Handle.h>
+#include <Buffer.h>
#include <Http.h>
namespace Balau {
@@ -18,6 +19,28 @@ class HttpWorker;
class HttpServer {
public:
+ class Response {
+ public:
+ Response(HttpServer * server, Http::Request req, IO<Handle> out) : m_server(server), m_req(req), m_out(out), m_buffer(new Buffer()), m_responseCode(200), m_type("text/html; charset=UTF-8"), m_flushed(false) { }
+ void SetResponseCode(int code) { m_responseCode = code; }
+ void SetContentType(const String & type) { m_type = type; }
+ IO<Buffer> get() { return m_buffer; }
+ IO<Buffer> operator->() { return m_buffer; }
+ void Flush();
+ void AddHeader(const String & line) { m_extraHeaders.push_front(line); }
+ void AddHeader(const String & key, const String & val) { AddHeader(key + ": " + val); }
+ private:
+ HttpServer * m_server;
+ Http::Request m_req;
+ IO<Handle> m_out;
+
+ IO<Buffer> m_buffer;
+ int m_responseCode;
+ String m_type;
+ std::list<String> m_extraHeaders;
+ bool m_flushed;
+ };
+
class Action {
public:
Action(const Regex & regex, const Regex & host = Regexes::any) : m_regex(regex), m_host(host), m_refCount(0) { }
@@ -48,6 +71,7 @@ class HttpServer {
Action::ActionMatch matches;
};
ActionFound findAction(const char * uri, const char * host);
+ String getServerName() { return "Balau/1.0"; }
private:
bool m_started;
void * m_listenerPtr;