26#ifndef HTTP_WITHOUT_FASTCGI
37 FCGX_FPrintF(request->out,
38 "Status: 404 Not Found\r\n"
39 "Content-Length: 0\r\n"
40 "Connection: close\r\n\r\n");
43 FCGX_FPrintF(request->out,
45 "Content-Type: %s\r\n"
46 "Content-Length: %d\r\n"
50 FCGX_PutStr(buf.c_str(), buf.length(), request->out);
97 :
THttpEngine(
"fastcgi",
"fastcgi interface to webserver"), fSocket(0), fDebugMode(
kFALSE), fTopName(),
98 fThrd(nullptr), fTerminating(
kFALSE)
129#ifndef HTTP_WITHOUT_FASTCGI
134 if ((args != 0) && (strlen(args) > 0)) {
138 while ((*args != 0) && (*args >=
'0') && (*args <=
'9'))
142 while ((*args != 0) && (*args !=
'?'))
162 Info(
"Create",
"Starting FastCGI server on port %s", sport.
Data() + 1);
171 Error(
"Create",
"ROOT compiled without fastcgi support");
180#ifndef HTTP_WITHOUT_FASTCGI
184 FCGX_Request request;
186 FCGX_InitRequest(&request, engine->
GetSocket(), 0);
192 int rc = FCGX_Accept_r(&request);
199 const char *inp_path = FCGX_GetParam(
"PATH_INFO", request.envp);
200 if (!inp_path) inp_path = FCGX_GetParam(
"SCRIPT_FILENAME", request.envp);
201 const char *inp_query = FCGX_GetParam(
"QUERY_STRING", request.envp);
202 const char *inp_method = FCGX_GetParam(
"REQUEST_METHOD", request.envp);
203 const char *inp_length = FCGX_GetParam(
"CONTENT_LENGTH", request.envp);
205 auto arg = std::make_shared<THttpCallArg>();
207 arg->SetPathAndFileName(inp_path);
209 arg->SetQuery(inp_query);
211 arg->SetMethod(inp_method);
216 len = strtol(inp_length, NULL, 10);
220 int nread = FCGX_GetStr((
char *)buf.data(), len, request.in);
222 arg->SetPostData(std::move(buf));
226 for (
char **envp = request.envp; *envp != NULL; envp++) {
229 if (entry[
n] ==
'=') {
236 arg->SetRequestHeader(header);
238 TString username = arg->GetRequestHeader(
"REMOTE_USER");
239 if ((username.
Length() > 0) && (arg->GetRequestHeader(
"AUTH_TYPE").Length() > 0))
240 arg->SetUserName(username);
243 FCGX_FPrintF(request.out,
"Status: 200 OK\r\n"
244 "Content-type: text/html\r\n"
246 "<title>FastCGI echo</title>"
247 "<h1>FastCGI echo</h1>\n");
249 FCGX_FPrintF(request.out,
"Request %d:<br/>\n<pre>\n", count);
250 FCGX_FPrintF(request.out,
" Method : %s\n", arg->GetMethod());
251 FCGX_FPrintF(request.out,
" PathName : %s\n", arg->GetPathName());
252 FCGX_FPrintF(request.out,
" FileName : %s\n", arg->GetFileName());
253 FCGX_FPrintF(request.out,
" Query : %s\n", arg->GetQuery());
254 FCGX_FPrintF(request.out,
" PostData : %ld\n", arg->GetPostDataLength());
255 FCGX_FPrintF(request.out,
"</pre><p>\n");
257 FCGX_FPrintF(request.out,
"Environment:<br/>\n<pre>\n");
258 for (
char **envp = request.envp; *envp != NULL; envp++) {
259 FCGX_FPrintF(request.out,
" %s\n", *envp);
261 FCGX_FPrintF(request.out,
"</pre><p>\n");
263 FCGX_Finish_r(&request);
271 FCGX_Finish_r(&request);
276 std::string hdr = arg->FillHttpHeader(
"Status:");
277 FCGX_FPrintF(request.out, hdr.c_str());
278 }
else if (arg->IsFile()) {
284 arg->CompressWithGzip();
286 std::string hdr = arg->FillHttpHeader(
"Status:");
287 FCGX_FPrintF(request.out, hdr.c_str());
289 FCGX_PutStr((
const char *)arg->GetContent(), (
int)arg->GetContentLength(), request.out);
292 FCGX_Finish_r(&request);
void FCGX_ROOT_send_file(FCGX_Request *request, const char *fname)
typedef void((*Func_t)())
TFastCgi()
normal constructor
TString fTopName
! name of top item
virtual Bool_t Create(const char *args)
initializes fastcgi variables and start thread, which will process incoming http requests
Bool_t fDebugMode
! debug mode, may required for fastcgi debugging in other servers
static void * run_func(void *)
virtual ~TFastCgi()
destructor
Int_t fSocket
! socket used by fastcgi
Bool_t fTerminating
! set when http server wants to terminate all engines
TThread * fThrd
! thread which takes requests, can be many later
THttpServer * GetServer() const
Returns pointer to THttpServer associated with engine.
Bool_t IsFileRequested(const char *uri, TString &res) const
Check if file is requested, thread safe.
Bool_t ExecuteHttp(std::shared_ptr< THttpCallArg > arg)
Execute HTTP request.
static char * ReadFileContent(const char *filename, Int_t &len)
Reads content of file from the disk.
static const char * GetMimeType(const char *path)
Guess mime type base on file extension.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
const char * Data() const
TString & Append(const char *cs)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Int_t Kill()
Kill this thread.
Int_t Run(void *arg=0)
Start the thread.
This class represents a WWW compatible URL.
const char * GetValueFromOptions(const char *key) const
Return a value for a given key from the URL options.
void ParseOptions() const
Parse URL options into a key/value map.