Send response object by the string.

6 views
Skip to first unread message

sanjeev kumar

unread,
Oct 10, 2011, 11:12:46 AM10/10/11
to Mordor Users
Hi Cody,

How to response the string object, not the fileStream.

For example:
{
std::string rStr =
"100097|Opened|Germany 30|40@5689.5;40@5689.0;40@5688.5;85@5688.3|
125@5691.0;40@5691.5;40@5692.5\n"
"100095|Opened|US Tech 100|30@2233.4;30@2233.2;51@2232.7|
30@2234.4;30@2234.6;51@2235.2\n"

MemoryStream::ptr mem(new MemoryStream);
mem->write(rStr.c_str(), rStr.length() +1);
return respondStream(request, mem);
}

throws fatal error:

2011-Oct-10 15:01:04.009260 6215329 FATAL 5917 0xcd16b30 : mordor/http/
server.cpp:824 ASSERTION: m_responseStream->size(== m_responseStream-
>tell()


Thanks
Sanjeev

Cody Cutrer

unread,
Oct 10, 2011, 11:20:59 AM10/10/11
to mordor...@googlegroups.com
The easiest way is simply:

{
std::string someResponse;
return respondError(request, Mordor::HTTP::OK, someResponse);
}

respondError is a bit of a misnomer - it's for sending responses with
no body, or very simple bodies that don't need to stream (such as the
string in this example).

If you're generating rStr on the fly from a variable amount of data,
I'd recommend against that, since then you'll have to be able to hold
the entire response in memory. Instead, either write directly to
request->responseStream() (setting up a chunked encoding yourself),
wrap the generation of your response in a custom Stream class that
generates more with each call to read, or use a PipeStream, giving one
end to respondStream, and (in another fiber), writing the response
into the other end.

Cody

Reply all
Reply to author
Forward
0 new messages