Fastcgi++: How to create 404 or 503 responses

c++, fastcgi, fastcgi++

Solution

The answer is basically as here:

https://web.archive.org/web/20160115021335/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.

Problem

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?

Original source