dsign dsign - 4 years ago 182
C++ Question

Fastcgi++: How to create 404 or 503 responses

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 =
// 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?

Answer Source

The answer is basically as here:


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download