【问题标题】:Fastcgi++: How to create 404 or 503 responsesFastcgi++:如何创建 404 或 503 响应
【发布时间】:2013-01-17 19:59:56
【问题描述】:

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;
    }
};

关于如何设置响应类型的任何想法?

【问题讨论】:

标签: c++ fastcgi fastcgi++


【解决方案1】:

答案基本如下:

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 就是这样。

【讨论】:

    猜你喜欢
    • 2012-12-25
    • 2012-08-29
    • 2020-09-14
    • 2019-10-07
    • 1970-01-01
    • 2012-02-08
    • 2012-07-06
    • 2012-02-07
    • 2015-02-11
    相关资源
    最近更新 更多