Actions
Feature #995
closedAllow suggestFileName in handleRequest (also WStreamResource::setMimeType())
Start date:
09/21/2011
Due date:
% Done:
0%
Estimated time:
Description
It matters especially in generating resources from custom model set to WTableView, for example where each resource created slows rendering if resource constructor must access database.
Access to database should be moved to handleRequest to allow generating mime type and suggested file name, for example. Here is a typical usage, that should be:
void MusicResource::handleRequest(const Wt::Http::Request& request,
Wt::Http::Response& response)
{
if (!request.continuation())
{
// here is a access to database moved from constructor (like in http://redmine.webtoolkit.eu/issues/994)
// we fetch from db a suggestedFileName and ext (extension)
this->suggestFileName(WString::fromUTF8(suggestedFileName));
string mimeType = Utils::findContentTypeByExt(ext);
if (!mimeType.empty())
this->setMimeType(mimeType);
if (this->m_generic_wstr.empty())
this->m_generic_wstr = ZenLib::Ztring(((SyNaT::MIR::SP::SyNaTPGApp::mcs_osid == POCO_OS_WINDOWS_NT ? "\\\\?\\" : "") + Poco::Path(sciezka_do_pliku, Poco::Path::PATH_UNIX).toString()).c_str()).To_Unicode();
}
tr->Commit();
}
catch(std::exception &e)
{
WApplication::instance()->log("error") << e.what();
}
}
try
{
if (!this->m_generic_wstr.empty())
{
boost::filesystem::ifstream f(m_generic_wstr, boost::filesystem::ifstream::binary);
this->handleRequestPiecewise(request, response, f);
}
}
catch(std::exception &e)
{
WApplication::instance()->log("error") << e.what();
}
}
Hope you will take this into consideration.
Updated by Koen Deforche about 13 years ago
- Status changed from New to Resolved
- Assignee set to Koen Deforche
- Target version set to 3.1.11
Hey,
This should be allowed with the latest git (and upcoming 3.1.11) --- you can now call suggestFileName() until the moment you access the output stream.
Also, you can call WResourceStream::setMimeType() from within handleRequest() ?
All this probably need some better documentation though.
Regards,
koen
Updated by Koen Deforche about 13 years ago
- Status changed from Resolved to Closed
Resolved in Wt 3.1.11
Actions