本文整理汇总了C++中onion::Response::setHeader方法的典型用法代码示例。如果您正苦于以下问题:C++ Response::setHeader方法的具体用法?C++ Response::setHeader怎么用?C++ Response::setHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类onion::Response
的用法示例。
在下文中一共展示了Response::setHeader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getSettingKinectWrapped
/* Like 'search_file' */
onion_connection_status OnionServer::getSettingKinectWrapped(
Onion::Request &req, Onion::Response &res)
{
const char* path = onion_request_get_fullpath( req.c_handler() );
#ifdef VERBOSE
printf("Request of %s.\n",path);
#endif
std::string filename("./html/");
filename.append(path);
std::ifstream file(filename.c_str());
std::string line;
if( file.is_open()){
/* Create header with mime type and charset information for several file extensions.
* This is just a workaround. There should be an automatic mechanicm
* in libonion. */
int periodPos = filename.find_last_of('.');
std::string extension = filename.substr(periodPos+1);
std::string key("Content-Type");
std::string defaultType("text/html; charset: utf-8");
std::string mime = m_mimedict.get( extension , defaultType ) ;
res.setHeader(key,mime);
onion_response_write_headers(res.c_handler());// missing in cpp bindings?
//res.writeHeaders();//this was added by me...
try{
/*
res.write("json_kinect = ", 14);
const char* kinect = m_settingKinect.getConfig(true);
size_t len = strlen( kinect );
res.write(kinect, (int) len );
res.write(";\n", 2 );
*/
while (std::getline(file, line)) {
res.write( line.c_str(), line.size() );
res.write("\n", 1 );
}
}//catch ( const boost::iobase::failure &ex )
catch ( const std::exception & ex ){
std::cerr << "Can not read " << filename << std::endl;
res.write( ErrReadFailed.c_str(), ErrReadFailed.size());
}
}else{
res.write( ErrNotFound.c_str(), ErrNotFound.size());
}
return OCS_PROCESSED;
}