Fastcgi ++:如何创建404或503响应 [英] Fastcgi++: How to create 404 or 503 responses

查看:216
本文介绍了Fastcgi ++:如何创建404或503响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Fastcgi ++是一个库,用于缓解C ++中fastcgi服务器的实现。这里是非常简单的用例,我想做:检查一个文件的存在,如果不存在,生成一些错误消息。这里是代码,寻找问题的迹象。

  struct the_fastcgi_server_t:Fastcgipp :: Request< char> 
{

bool response()
{
使用命名空间Fastcgipp;

Fastcgipp :: Http :: Environment< char> const& env =
this-> environment();
//我可以解析文件吗?
std :: string target_js;
try {
target_js = path_processor(env.scriptName);
} catch(file_not_found_exc_t const& e)
{
// TODO如何在这里设置标准404?
return true;
}

out<< Content-Type:text / javascript; charset = utf-8 \r\\\
\r\\\
;

// ...这里我填写响应。

return true;
}
};关于如何设置响应类型的任何想法?

=h2_lin>解决方案

答案基本上如下:



http://www.fastcgi.com/docs/faq.html#httpstatus



也就是说,使用像这样的代码片段

  out< 状态:404未找到\r\\\
\r\\\
;

。它不是标准的http,但FastCGI只是一个包装CGI,这就是如何CGI。


Fastcgi++ is a library for easing the implementation of fastcgi servers in C++. And here is the very simple use case that I want to do: to check for the existence of a file, and if doesn't exist, to generate some error message. Here is the code, look for the question signs.

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

Any ideas about how to set the response type?

解决方案

The answer is basically as here:

http://www.fastcgi.com/docs/faq.html#httpstatus

That is, use a fragment of code like this one

 out << "Status: 404 Not found\r\n\r\n";

in the response method. It is not standard http, but FastCGI is just a wrapper over CGI, and that's how CGI does it.

这篇关于Fastcgi ++:如何创建404或503响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆