如何创建404或503响应
Fastcgi++: How to create 404 or 503 responses
Fastcgi++是一个简化在c++中实现Fastcgi服务器的库。这是我想做的一个非常简单的用例:检查文件是否存在,如果不存在,则生成一些错误消息。下面是代码,查找问号
struct the_fastcgi_server_t: Fastcgipp::Request<char>
{
bool response()
{
using namespace Fastcgipp;
Fastcgipp::Http::Environment<char> const &env =
this->environment();
// Can I resolve the file?
std::string target_js;
try {
target_js = path_processor( env.scriptName );
} catch ( file_not_found_exc_t const& e )
{
// TODO How do I set a standard 404 here???!!
return true;
}
out << "Content-Type: text/javascript; charset=utf-8rnrn";
// ... Here I fill the response.
return true;
}
};
关于如何设置响应类型有什么想法吗?
答案基本如下:
https://web.archive.org/web/20160115021335/http://www.fastcgi.com/docs/faq.html httpstatus
也就是说,使用像这样的代码片段
out << "Status: 404 Not foundrnrn";
中的响应方法。它不是标准的http,但FastCGI只是CGI的包装,这就是CGI的工作方式。
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 使用std::multimap迭代器创建std::list
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 使用CMake创建QML插件
- 如何在c++中为模板函数实例创建快捷方式
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 试图在visual studio上用C++创建一个桌面应用程序
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 如何在C++20中创建模板别名的推导指南
- 如何为模板化对象创建模板向量?VS正在投掷C3203
- 如何创建一个空的全局类并在启动时实例化它
- 无法创建抽象类的实例
- 链接到自行创建的dll失败
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- Shell_NotifyIcon在系统托盘中创建空白、无响应的图标
- 创建响应式 Windows winapi c++
- 具有动态创建控件的MFC应用程序突然停止响应
- 如何创建404或503响应