Hobrasoft httpd server
Embedded HTTP server for Qt and C++
requestmapper.cpp
Go to the documentation of this file.
1 
7 #include "requestmapper.h"
8 #include "httprequest.h"
9 #include "httpresponse.h"
10 #include "httpconnection.h"
11 #include "staticfilecontroller.h"
13 
14 using namespace HobrasoftHttpd;
15 using namespace Example::Httpd;
16 
17 
18 RequestMapper::~RequestMapper() {
19 }
20 
21 
22 RequestMapper::RequestMapper(HobrasoftHttpd::HttpConnection *parent) : HobrasoftHttpd::HttpRequestHandler(parent) {
23 }
24 
25 
26 void RequestMapper::service(HttpRequest *request, HttpResponse *response) {
27  QString path = request->path();
28 
29  #define ROUTER(adresa, trida) \
30  if (path.startsWith(adresa)) { \
31  HttpRequestHandler *controller = new trida (connection()); \
32  controller->service(request, response); \
33  return; \
34  }
35 
36  ROUTER("/example", ControllerExample);
37 
38  HttpRequestHandler::service(request, response);
39  response->flush();
40 
41 }
42 
HttpResponse * response()
Returns new instance of HttpResponse class.
QString path() const
Returns path of the request (/files/index.html)
Definition: httprequest.h:78
Processes requests with path /example.
Name space for own application HTTP server.
void flush()
Writes last part of the response and closes the socket when possible.
Response to HTTP request - headers, cookies and body.
Definition: httpresponse.h:30
Processes incoming requests.
void service(HobrasoftHttpd::HttpRequest *request, HobrasoftHttpd::HttpResponse *response)
Processes the request.
Processes HTTP request, parses headers, body and files sent by HTTP protocol.
Definition: httprequest.h:23
Namespace of HTTP server.
One single connection to http server.