forked from dedis/Dissent
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWebServer.hpp
58 lines (46 loc) · 1.39 KB
/
WebServer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef DISSENT_WEB_WEB_SERVER_H_GUARD
#define DISSENT_WEB_WEB_SERVER_H_GUARD
#include <QScopedPointer>
#include <QSharedPointer>
#include "qhttpserver.h"
#include "qhttprequest.h"
#include "qhttpresponse.h"
#include "Utils/StartStopSlots.hpp"
#include "WebService.hpp"
namespace Dissent {
namespace Web {
class WebServer : public Utils::StartStopSlots {
Q_OBJECT
public:
WebServer(const QUrl &host);
virtual ~WebServer();
/**
* Called to start
*/
virtual bool Start();
/**
* Called to stop
*/
virtual bool Stop();
/**
* Add a route to the routing table.
* @param method the method to route (GET, POST, etc)
* @param path the base path to route (without query string)
* @param service the routing destination service
* @returns returns true if successfully added
*/
bool AddRoute(QHttpRequest::HttpMethod method, const QString &path,
const QSharedPointer<WebService> &service);
private:
typedef QPair<QHttpRequest::HttpMethod, QString> ServiceId;
QHash<ServiceId, QSharedPointer<WebService> > m_services;
QScopedPointer<QHttpServer> m_server;
QUrl m_host;
QHash<QHttpRequest *, QHttpResponse *> m_requests;
private slots:
void HandleRequest(QHttpRequest *request, QHttpResponse *response);
void RequestReady();
};
}
}
#endif