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 const char *inp_query = FCGX_GetParam(
"QUERY_STRING", request.envp);
201 const char *inp_method = FCGX_GetParam(
"REQUEST_METHOD", request.envp);
202 const char *inp_length = FCGX_GetParam(
"CONTENT_LENGTH", request.envp);
204 auto arg = std::make_shared<THttpCallArg>();
206 arg->SetPathAndFileName(inp_path);
208 arg->SetQuery(inp_query);
210 arg->SetMethod(inp_method);
215 len = strtol(inp_length, NULL, 10);
219 int nread = FCGX_GetStr((
char *)buf.data(), len, request.in);
221 arg->SetPostData(std::move(buf));
225 for (
char **envp = request.envp; *envp != NULL; envp++) {
228 if (entry[
n] ==
'=') {
235 arg->SetRequestHeader(header);
237 TString username = arg->GetRequestHeader(
"REMOTE_USER");
238 if ((username.
Length() > 0) && (arg->GetRequestHeader(
"AUTH_TYPE").Length() > 0))
239 arg->SetUserName(username);
242 FCGX_FPrintF(request.out,
"Status: 200 OK\r\n"
243 "Content-type: text/html\r\n"
245 "<title>FastCGI echo</title>"
246 "<h1>FastCGI echo</h1>\n");
248 FCGX_FPrintF(request.out,
"Request %d:<br/>\n<pre>\n", count);
249 FCGX_FPrintF(request.out,
" Method : %s\n", arg->GetMethod());
250 FCGX_FPrintF(request.out,
" PathName : %s\n", arg->GetPathName());
251 FCGX_FPrintF(request.out,
" FileName : %s\n", arg->GetFileName());
252 FCGX_FPrintF(request.out,
" Query : %s\n", arg->GetQuery());
253 FCGX_FPrintF(request.out,
" PostData : %ld\n", arg->GetPostDataLength());
254 FCGX_FPrintF(request.out,
"</pre><p>\n");
256 FCGX_FPrintF(request.out,
"Environment:<br/>\n<pre>\n");
257 for (
char **envp = request.envp; *envp != NULL; envp++) {
258 FCGX_FPrintF(request.out,
" %s\n", *envp);
260 FCGX_FPrintF(request.out,
"</pre><p>\n");
262 FCGX_Finish_r(&request);
270 FCGX_Finish_r(&request);
275 std::string hdr = arg->FillHttpHeader(
"Status:");
276 FCGX_FPrintF(request.out, hdr.c_str());
277 }
else if (arg->IsFile()) {
283 arg->CompressWithGzip();
285 std::string hdr = arg->FillHttpHeader(
"Status:");
286 FCGX_FPrintF(request.out, hdr.c_str());
288 FCGX_PutStr((
const char *)arg->GetContent(), (
int)arg->GetContentLength(), request.out);
291 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.