mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-21 06:37:42 +01:00
changes to allow extension to RequestHandler
This commit is contained in:
parent
4e7a55a24b
commit
ae50bc2ad2
@ -40,19 +40,17 @@
|
||||
#define WebWidgets_RequestHandler_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/WebWidgets/WebWidgets.h"
|
||||
#include "Poco/WebWidgets/WebApplication.h"
|
||||
#include "Poco/Net/HTTPRequestHandler.h"
|
||||
#include "Poco/Net/NameValueCollection.h"
|
||||
#include "Poco/Net/HTMLForm.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
|
||||
|
||||
class WebApplication;
|
||||
|
||||
|
||||
class WebWidgets_API RequestHandler: public Poco::Net::HTTPRequestHandler
|
||||
/// The HTTP request handler for WebWidgets.
|
||||
{
|
||||
@ -60,7 +58,7 @@ public:
|
||||
static const std::string KEY_ID; /// key for form param contains id
|
||||
static const std::string KEY_EVID; /// form param containing the event name
|
||||
|
||||
RequestHandler(WebApplication& app);
|
||||
RequestHandler(Poco::SharedPtr<WebApplication> pApp);
|
||||
/// Creates the RequestHandler, using the given WebApplication.
|
||||
|
||||
virtual ~RequestHandler();
|
||||
@ -70,17 +68,47 @@ public:
|
||||
void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response);
|
||||
|
||||
protected:
|
||||
RequestHandler();
|
||||
/// Creates the RequestHandler, without any app
|
||||
|
||||
void handlePageRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response);
|
||||
void handleAjaxRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response, const Poco::Net::NameValueCollection& args);
|
||||
void handleForm(const Poco::Net::HTMLForm& form);
|
||||
static void parseRequest(const Poco::Net::HTTPServerRequest& request, Poco::Net::NameValueCollection& nvc);
|
||||
static void parseRequest(const std::string& path, Poco::Net::NameValueCollection& nvc);
|
||||
|
||||
Poco::SharedPtr<WebApplication> app();
|
||||
/// Returns the application
|
||||
|
||||
Poco::SharedPtr<WebApplication> app() const;
|
||||
/// Returns the application
|
||||
|
||||
void setApp(Poco::SharedPtr<WebApplication> pApp);
|
||||
/// Sets the application at the requesthandler
|
||||
|
||||
private:
|
||||
WebApplication& _app;
|
||||
Poco::SharedPtr<WebApplication> _pApp;
|
||||
};
|
||||
|
||||
|
||||
inline Poco::SharedPtr<WebApplication> RequestHandler::app()
|
||||
{
|
||||
return _pApp;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::SharedPtr<WebApplication> RequestHandler::app() const
|
||||
{
|
||||
return _pApp;
|
||||
}
|
||||
|
||||
|
||||
inline void RequestHandler::setApp(Poco::SharedPtr<WebApplication> pApp)
|
||||
{
|
||||
_pApp = pApp;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::WebWidgets
|
||||
|
||||
|
||||
|
@ -60,9 +60,14 @@ const std::string RequestHandler::KEY_ID("id");
|
||||
const std::string RequestHandler::KEY_EVID("evId");
|
||||
|
||||
|
||||
RequestHandler::RequestHandler():
|
||||
_pApp()
|
||||
{
|
||||
}
|
||||
|
||||
RequestHandler::RequestHandler(WebApplication& app):
|
||||
_app(app)
|
||||
|
||||
RequestHandler::RequestHandler(Poco::SharedPtr<WebApplication> app):
|
||||
_pApp(app)
|
||||
{
|
||||
}
|
||||
|
||||
@ -74,7 +79,7 @@ RequestHandler::~RequestHandler()
|
||||
|
||||
void RequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
|
||||
{
|
||||
_app.attachToThread(request);
|
||||
_pApp->attachToThread(request);
|
||||
Poco::Net::NameValueCollection args;
|
||||
parseRequest(request, args);
|
||||
|
||||
@ -109,8 +114,8 @@ void RequestHandler::handlePageRequest(Poco::Net::HTTPServerRequest& request, Po
|
||||
response.setChunkedTransferEncoding(true);
|
||||
response.setContentType("text/html");
|
||||
std::ostream& str = response.send();
|
||||
RenderContext renderContext(*_app.getLookAndFeel(), _app);
|
||||
Page::Ptr pPage = _app.getCurrentPage();
|
||||
RenderContext renderContext(*_pApp->getLookAndFeel(), *_pApp);
|
||||
Page::Ptr pPage = _pApp->getCurrentPage();
|
||||
if (pPage)
|
||||
{
|
||||
pPage->renderHead(renderContext, str);
|
||||
@ -132,7 +137,7 @@ void RequestHandler::handleAjaxRequest(Poco::Net::HTTPServerRequest& request, Po
|
||||
const std::string id = it->second;
|
||||
|
||||
it = args.begin();
|
||||
RequestProcessor* pProc = _app.getAjaxProcessor(id);
|
||||
RequestProcessor* pProc = _pApp->getAjaxProcessor(id);
|
||||
if (!pProc)
|
||||
{
|
||||
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR, "no requestprocessor found");
|
||||
@ -172,7 +177,7 @@ void RequestHandler::handleAjaxRequest(Poco::Net::HTTPServerRequest& request, Po
|
||||
|
||||
void RequestHandler::handleForm(const Poco::Net::HTMLForm& form)
|
||||
{
|
||||
_app.handleForm(form);
|
||||
_pApp->handleForm(form);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user