本文整理汇总了C++中HttpResponse::SetBody方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpResponse::SetBody方法的具体用法?C++ HttpResponse::SetBody怎么用?C++ HttpResponse::SetBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponse
的用法示例。
在下文中一共展示了HttpResponse::SetBody方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HttpResponse
HttpResponse *
EHS::RouteRequest ( HttpRequest * ipoHttpRequest ///< request info for service
)
{
// get the next path from the URI
std::string sNextPathPart = GetNextPathPart ( ipoHttpRequest->sUri );
EHS_TRACE ( "Info: Trying to route: '%s'\n", sNextPathPart.c_str ( ) );
// if there is no more path, call HandleRequest on this EHS object with
// whatever's left - or if we're not routing
if ( sNextPathPart.empty ( ) ||
m_oEHSServerParameters.find ( "norouterequest" ) !=
m_oEHSServerParameters.end ( ) ) {
// create an HttpRespose object for the client
HttpResponse * poHttpResponse =
new HttpResponse ( ipoHttpRequest->m_nRequestId,
ipoHttpRequest->m_poSourceEHSConnection );
// get the actual response and return code
poHttpResponse->m_nResponseCode =
HandleRequest ( ipoHttpRequest, poHttpResponse );
return poHttpResponse;
}
// if the path exists, check it against the map of EHSs
if ( oEHSMap [ sNextPathPart ] ) {
// if it exists, call RouteRequest with that EHS and the
// new shortened path
return oEHSMap [ sNextPathPart ]->RouteRequest ( ipoHttpRequest );
}
// if it doesn't exist, send an error back up saying resource doesn't exist
else {
EHS_TRACE ( "Info: Routing failed. Most likely caused by an invalid URL, not internal error\n" );
// send back a 404 response
HttpResponse * poHttpResponse = new HttpResponse ( ipoHttpRequest->m_nRequestId,
ipoHttpRequest->m_poSourceEHSConnection );
poHttpResponse->m_nResponseCode = HTTPRESPONSECODE_404_NOTFOUND;
poHttpResponse->SetBody ( "404 - Not Found", strlen ( "404 - Not Found" ) );
return poHttpResponse;
}
}
示例2: msg
HttpResponse *HandleThreadException(ehs_threadid_t, HttpRequest *request, exception &ex)
{
HttpResponse *ret = NULL;
string msg(ex.what());
cerr << "##################### Catched " << msg << endl;
cerr << "request: " << hex << request << dec << endl;
tracing::exception *btx =
dynamic_cast<tracing::exception*>(&ex);
if (NULL != btx) {
string tmsg = btx->where();
cerr << "Backtrace:" << endl << tmsg;
if (0 != msg.compare("fatal")) {
ret = HttpResponse::Error(HTTPRESPONSECODE_500_INTERNALSERVERERROR, request);
string body(ret->GetBody());
tmsg.insert(0, "<br>\n<pre>").append(msg).append("</pre><p><a href=\"/\">Back to main page</a>");
body.insert(body.find("</body>"), tmsg);
ret->SetBody(body.c_str(), body.length());
}
}
return ret;
}