本文整理汇总了C++中http_request::get_path_info方法的典型用法代码示例。如果您正苦于以下问题:C++ http_request::get_path_info方法的具体用法?C++ http_request::get_path_info怎么用?C++ http_request::get_path_info使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http_request
的用法示例。
在下文中一共展示了http_request::get_path_info方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_request
http_response www_server::on_request(const http_request &req) {
http_response resp;
// we are support only HTTP GET method
if (req.get_method() != http_method::get) {
resp.set_status(http_error::method_not_allowed);
resp.set_allow(http_method::get);
resp.set_content("The POST requests are not supported yet.");
return resp;
}
// obtain the name of the file requested
url u(req.get_path_info());
u.normalize(root_dir);
// load file content to the server response
try {
ifstream in(u.path.c_str());
// if file can't be open, throw an error
if (!in)
throw dbp::exception(string("File not found: ") + u.path);
// set file content type
resp.set_content_type(mime(u.path));
// load file
resp.add_content(in);
}
catch (dbp::exception &e) {
// return error message
resp.set_status(http_error::not_found);
resp.set_content(e.what());
}
return resp;
}