Bug #994
closedWStreamResource pushes Content-Disposition in resource contents...
0%
Description
I have custom WStreamResource which looks like this:
class ParamsResource : public WStreamResource
{
public:
ParamsResource(DatabaseModule *dm, long long utwId, WObject *parent = 0);
virtual ~ParamsResource();
virtual void handleRequest(const Wt::Http::Request& request,
Wt::Http::Response& response);
protected:
DatabaseModule *m_dm;
long long m_utwId;
stringstream m_ss_response;
};
ParamsResource::ParamsResource(DatabaseModule *dm,
long long utwId, WObject *parent) :
WStreamResource(parent), m_dm(dm), m_utwId(utwId)
{
this->setBufferSize(100 * 1024);
try
{
Transaction tr = this->m_dm->createTransaction(amRead,
ilReadCommitted, lrWait);
tr->Start();
ostringstream sql;
sql << "select GAT_GATUNEK || '_' || ART_NAZWA_ARTYSTY || '_' "
" || ALB_NAZWA_ALBUMU || '_' || UTW_TYTUL_UTWORU "
" from MIR_NAZARTNAZALBITP "
" where UTW_ID = "
<< this->m_utwId;
string sqlstmt = sql.str();
Statement stmt = this->m_dm->createStatement(&tr);
stmt->Prepare(sqlstmt);
stmt->Execute();
if (stmt->Fetch())
{
bool isIE = WApplication::instance()->environment().userAgent().find("MSIE") != string::npos;
bool isChrome = WApplication::instance()->environment().userAgent().find("Chrome") != string::npos;
bool isLynx = WApplication::instance()->environment().userAgent().find("Lynx") != string::npos;
ostringstream oss;
string suggestedFileName;
if (!(isIE || isChrome || isLynx))
{
string dbS;
stmt->Get(1, dbS);
oss << dbS;
}
else
{
oss << "utwor" << this->m_utwId;
}
suggestedFileName = oss.str();
if (suggestedFileName.length() > 250)
suggestedFileName = suggestedFileName.substr(0, 250);
suggestedFileName += ".csv";
UnicodeString icusuggestedFileName = UnicodeString::fromUTF8(suggestedFileName).findAndReplace("\"", "_");
suggestedFileName.clear();
icusuggestedFileName.toUTF8String(suggestedFileName);
this->suggestFileName(suggestedFileName);
this->setMimeType("text/csv");
}
tr->Commit();
}
catch(std::exception &e)
{
WApplication::instance()->log("error") << e.what();
}
}
ParamsResource::~ParamsResource()
{
this->beingDeleted();
}
void ParamsResource::handleRequest(const Wt::Http::Request& request,
Wt::Http::Response& response)
{
if (this->m_ss_response.gcount() == 0)
{
ostringstream oss;
string str_response, param;
string::size_type dotPos;
ostringstream sql;
sql << "select * from MIR_PARAMETRY "
" where PAR_UTW_ID = " << this->m_utwId;
try
{
Transaction tr = this->m_dm->createTransaction(amRead,
ilReadCommitted, lrWait);
tr->Start();
string sqlstmt = sql.str();
Statement stmt = this->m_dm->createStatement(&tr);
stmt->Prepare(sqlstmt);
stmt->Execute();
if (stmt->Fetch())
{
string paramsNames[173];
double params[173];
for (int i = 4; i < 4 + 173; i++)
{
stmt->Get(i, params[i - 4]);
paramsNames[i - 4] = stmt->ColumnName(i);
}
this->m_ss_response << paramsNames[0].substr(4);
for(int i = 1; i < 173; i++)
{
this->m_ss_response << ";" << paramsNames[i].substr(4);
}
this->m_ss_response << "\r\n";
oss.setf(ios::fixed, ios::floatfield);
oss.precision(18);
oss.str("");
oss << params[0];
param = oss.str();
dotPos = param.find(".");
param.replace(dotPos, 1, ",");
this->m_ss_response << param;
for(int i = 1; i < 173; i++)
{
oss.str("");
oss << params[i];
param = oss.str();
dotPos = param.find(".");
param.replace(dotPos, 1, ",");
this->m_ss_response << ";" << param;
}
}
tr->Commit();
}
catch(std::exception &e)
{
WApplication::instance()->log("warn") << e.what();
}
}
this->handleRequestPiecewise(request, response, this->m_ss_response);
}
You can test this resource in http://synat.eti.pg.gda.pl where you can login as lukasz and password of anakin
The Content-Disposition header with filename is inside contents of response (that is file created at client side).
You probably should change order of headers flushed to client....
I have used the git version from 18.09.2011.
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,
Ooops indeed. This is a deployment using FastCGI, I guess (since I found the bug there) ?
I've committed an (untested) fix in git.
Regards,
koen
Updated by Łukasz Matuszewski about 13 years ago
Yes... with latest git it works as expected... even inside handleRequest method.
Off topic:
How can i update my git repo (that is you repo at http://www.webtoolkit.eu/git/wt.git) which will work just as svn update ? I am absolutely newbie in git system.
Updated by Koen Deforche about 13 years ago
- Status changed from Resolved to Closed
Resolved in Wt 3.1.11