mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-14 23:07:56 +02:00
Changed Ajax request detection to prevent browser caching
This commit is contained in:
@@ -485,9 +485,14 @@ std::string Utility::createURI(const std::map<std::string, std::string>& addPara
|
|||||||
WebApplication& app = WebApplication::instance();
|
WebApplication& app = WebApplication::instance();
|
||||||
Renderable::ID id = app.getCurrentPage()->id();
|
Renderable::ID id = app.getCurrentPage()->id();
|
||||||
std::ostringstream uri;
|
std::ostringstream uri;
|
||||||
uri << "'" << app.getURI().toString() << "?";
|
std::string theUri(app.getURI().toString());
|
||||||
uri << RequestHandler::KEY_TYPE << "=" << RequestHandler::VAL_AJAX; //mark as AJAX request
|
if (theUri.empty())
|
||||||
uri << "&" << RequestHandler::KEY_ID << "=" << id;
|
theUri = "/";
|
||||||
|
else if (theUri[theUri.length()-1] != '/')
|
||||||
|
theUri.append("/");
|
||||||
|
uri << "'" << theUri;
|
||||||
|
uri << ";"; //mark as AJAX request
|
||||||
|
uri << RequestHandler::KEY_ID << "=" << id;
|
||||||
// add optional params
|
// add optional params
|
||||||
bool commaAtEnd = false;
|
bool commaAtEnd = false;
|
||||||
std::size_t cnt(1);
|
std::size_t cnt(1);
|
||||||
|
@@ -59,8 +59,6 @@ class WebWidgets_API RequestHandler: public Poco::Net::HTTPRequestHandler
|
|||||||
public:
|
public:
|
||||||
static const std::string KEY_ID; /// key for form param contains id
|
static const std::string KEY_ID; /// key for form param contains id
|
||||||
static const std::string KEY_EVID; /// form param containing the event name
|
static const std::string KEY_EVID; /// form param containing the event name
|
||||||
static const std::string VAL_AJAX; /// value to detect an AJAX request
|
|
||||||
static const std::string KEY_TYPE; /// key identifying the type of request
|
|
||||||
|
|
||||||
RequestHandler(WebApplication& app);
|
RequestHandler(WebApplication& app);
|
||||||
/// Creates the RequestHandler, using the given WebApplication.
|
/// Creates the RequestHandler, using the given WebApplication.
|
||||||
|
@@ -56,8 +56,6 @@ namespace WebWidgets {
|
|||||||
|
|
||||||
const std::string RequestHandler::KEY_ID("id");
|
const std::string RequestHandler::KEY_ID("id");
|
||||||
const std::string RequestHandler::KEY_EVID("evId");
|
const std::string RequestHandler::KEY_EVID("evId");
|
||||||
const std::string RequestHandler::VAL_AJAX("ajax");
|
|
||||||
const std::string RequestHandler::KEY_TYPE("appinf");
|
|
||||||
|
|
||||||
|
|
||||||
RequestHandler::RequestHandler(WebApplication& app):
|
RequestHandler::RequestHandler(WebApplication& app):
|
||||||
@@ -74,28 +72,21 @@ RequestHandler::~RequestHandler()
|
|||||||
void RequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
|
void RequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
|
||||||
{
|
{
|
||||||
_app.attachToThread();
|
_app.attachToThread();
|
||||||
Poco::Net::HTMLForm form(request, request.stream());
|
Poco::Net::NameValueCollection args;
|
||||||
if (!form.empty())
|
parseRequest(request, args);
|
||||||
|
if (args.empty())
|
||||||
{
|
{
|
||||||
Poco::Net::NameValueCollection::ConstIterator it = form.find(KEY_TYPE);
|
Poco::Net::HTMLForm form(request, request.stream());
|
||||||
if (it != form.end())
|
if (!form.empty())
|
||||||
{
|
{
|
||||||
if (it->second == VAL_AJAX)
|
|
||||||
{
|
|
||||||
form.erase(KEY_TYPE);
|
|
||||||
handleAjaxRequest(request, response, form);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
form.erase(KEY_TYPE);
|
|
||||||
handleForm(form);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
handleForm(form);
|
handleForm(form);
|
||||||
|
}
|
||||||
|
handlePageRequest(request, response);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
handlePageRequest(request, response);
|
{
|
||||||
|
handleAjaxRequest(request, response, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user