HTTP request handler

Whenever POCO's HTTP server receives a new client connection, it uses a new instance of our RequestHandlerFactory class to get a handler for the specific request. Because it's such a simple class, it's fully implemented in the header:

#include <Poco/Net/HTTPRequestHandlerFactory.h>
#include <Poco/Net/HTTPServerRequest.h>

using namespace Poco::Net;

#include "statushandler.h"
#include "datahandler.h"


class RequestHandlerFactory: public HTTPRequestHandlerFactory {
public:
RequestHandlerFactory() {}
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request) {
if (request.getURI().compare(0, 12, "/clubstatus/") == 0) { return new StatusHandler(); }
else { return new DataHandler(); }
}
};

Our class doesn't do a whole lot more than compare the URL that the HTTP server was provided to determine which type of handler to instantiate and return. Here, we can see that if the URL string starts with /clubstatus, we return the status handler, which implements the REST API.

The default handler is a simple file server, which attempts to interpret the request as a filename, as we will see in a moment.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.31.125