21 #ifndef DABC_WITHOUT_FASTCGI
29 std::ifstream is(fname);
39 buf = (
char*) malloc(length);
48 FCGX_FPrintF(request->out,
49 "Status: 404 Not Found\r\n"
50 "Content-Length: 0\r\n"
51 "Connection: close\r\n\r\n");
71 FCGX_FPrintF(request->out,
73 "Content-Type: %s\r\n"
74 "Content-Length: %d\r\n"
77 FCGX_PutStr(buf, length, request->out);
120 std::string sport =
":9000";
123 #ifndef DABC_WITHOUT_FASTCGI
126 DOUT0(
"Starting FastCGI server on port %s", sport.c_str());
128 fSocket = FCGX_OpenSocket(sport.c_str(), 10);
134 EOUT(
"DABC compiled without FastCgi support");
142 #ifndef DABC_WITHOUT_FASTCGI
146 FCGX_Request request;
148 FCGX_InitRequest(&request, server->
fSocket, 0);
154 int rc = FCGX_Accept_r(&request);
160 const char* inp_path = FCGX_GetParam(
"PATH_INFO", request.envp);
161 if (!inp_path) inp_path = FCGX_GetParam(
"SCRIPT_FILENAME", request.envp);
162 const char* inp_query = FCGX_GetParam(
"QUERY_STRING", request.envp);
166 FCGX_FPrintF(request.out,
168 "Content-type: text/html\r\n"
170 "<title>FastCGI echo (fcgiapp version)</title>"
171 "<h1>FastCGI echo (fcgiapp version)</h1>\n"
172 "Request number %d<p>\n", count);
174 const char *contentLength = FCGX_GetParam(
"CONTENT_LENGTH", request.envp);
177 if (contentLength != NULL)
178 len = strtol(contentLength, NULL, 10);
181 FCGX_FPrintF(request.out,
"No data from standard input.<p>\n");
186 FCGX_FPrintF(request.out,
"Standard input:<br/>\n<pre>\n");
187 for (i = 0; i < len; i++) {
188 if ((ch = FCGX_GetChar(request.in)) < 0) {
189 FCGX_FPrintF(request.out,
"Error: Not enough bytes received on standard input<p>\n");
192 FCGX_PutChar(ch, request.out);
194 FCGX_FPrintF(request.out,
"\n</pre><p>\n");
197 FCGX_FPrintF(request.out,
"URI: %s<p>\n", inp_path);
198 FCGX_FPrintF(request.out,
"QUERY: %s<p>\n", inp_query ? inp_query :
"---");
199 FCGX_FPrintF(request.out,
"<p>\n");
201 FCGX_FPrintF(request.out,
"Environment:<br/><pre>");
202 for(
char** envp = request.envp; *envp != NULL; envp++) {
203 FCGX_FPrintF(request.out,
"%s\n", *envp);
205 FCGX_FPrintF(request.out,
"</pre><p>");
207 FCGX_Finish_r(&request);
212 std::string content_type, content_header, content_str;
217 FCGX_Finish_r(&request);
221 if (!server->
Process(inp_path, inp_query,
222 content_type, content_header, content_str, content_bin)) {
223 FCGX_FPrintF(request.out,
"Status: 404 Not Found\r\n"
224 "Content-Length: 0\r\n"
225 "Connection: close\r\n\r\n");
228 if (content_type==
"__file__") {
232 if (!content_bin.
null()) {
233 FCGX_FPrintF(request.out,
235 "Content-Type: %s\r\n"
237 "Content-Length: %ld\r\n"
238 "Connection: keep-alive\r\n"
240 content_type.c_str(),
241 content_header.c_str(),
248 FCGX_FPrintF(request.out,
250 "Content-Type: %s\r\n"
252 "Content-Length: %d\r\n"
255 content_type.c_str(),
256 content_header.c_str(),
257 content_str.length(),
258 content_str.c_str());
261 FCGX_Finish_r(&request);
void FCGX_DABC_send_file(FCGX_Request *request, const char *fname)
Reference on memory from memory pool.
BufferSize_t GetTotalSize() const
Return total size of all buffer segments.
void * SegmentPtr(unsigned n=0) const
Returns pointer on the segment, no any boundary checks.
Represents command with its arguments.
class represents posix pthread functionality
bool AsBool(bool dflt=false) const
int64_t AsInt(int64_t dflt=0) const
bool null() const
Returns true if reference contains nullptr.
virtual void OnThreadAssigned()
RecordField Cfg(const std::string &name, Command cmd=nullptr) const
Returns configuration field of specified name Configuration value of specified name searched in follo...
Server provides fastcgi access to DABC
int fCgiPort
configured fast cgi port, default 9000
bool fDebugMode
when true, only debug info returned by server
virtual void OnThreadAssigned()
int fSocket
fastcgi server socket
static void * RunFunc(void *arg)
FastCgi(const std::string &name, dabc::Command cmd=nullptr)
Server provides http access to DABC
bool IsFileRequested(const char *uri, std::string &fname)
Check if file is requested.
bool Process(const char *uri, const char *query, std::string &content_type, std::string &content_header, std::string &content_str, dabc::Buffer &content_bin)
Method process different URL requests, should be called from server thread.
static const char * GetMimeType(const char *fname)
std::string format(const char *fmt,...)