forked from dedis/Dissent
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEchoService.hpp
50 lines (42 loc) · 1.11 KB
/
EchoService.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
#ifndef DISSENT_WEB_ECHO_SERVICE_GUARD
#define DISSENT_WEB_ECHO_SERVICE_GUARD
#include <QtCore>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QUrlQuery>
#endif
#include <QByteArray>
#include <QList>
#include "MessageWebService.hpp"
namespace Dissent {
namespace Web {
/**
* Web service for echoing the body of the requester
*/
class EchoService : public WebService {
public:
explicit EchoService()
{
}
virtual ~EchoService() {}
/**
* Called to handle the incoming request
* @param request the incoming request
* @param response used to respond to the rqeuest
*/
virtual void HandleRequest(QHttpRequest *request, QHttpResponse *response)
{
if(request->method() == QHttpRequest::HTTP_POST) {
SendResponse(response, request->body());
} else {
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QByteArray rmsg = request->url().encodedQuery();
#else
QByteArray rmsg = request->url().query(QUrl::FullyEncoded).toLatin1();
#endif
SendResponse(response, rmsg);
}
}
};
}
}
#endif