c++ - Fastcgi++:如何创建 404 或 503 响应

标签 c++ fastcgi fastcgi++

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-8\r\n\r\n";

        // ... 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 found\r\n\r\n";

在响应方法中。它不是标准的 http,但 FastCGI 只是 CGI 的包装器,这就是 CGI does it .

关于c++ - Fastcgi++:如何创建 404 或 503 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14387122/

相关文章:

linux - 需要有关 Nginx CGI 配置的帮助

c++ - 管道 "address system"

boost - 安装FastCGI++

ubuntu - ubuntu 上 Fastcgi 的问题

jquery - 使用 fastcgi++ 和 json-spirit 读取和解析 POST JSON

C++ 映射变量地址?

c++ - 我需要使用具有 C++ 的 add() 和 remove() 函数的字符串创建一个优先级队列

c++ - 在文本中查找特定标记并验证它们(RegExp?)

使用 zeroMQ 或 boost.asio 的 C++ 数据包嗅探器

php - 从 FasctCGI 返回响应到 nginx