26 #ifndef HTTP_WITHOUT_FASTCGI 39 FCGX_FPrintF(request->out,
40 "Status: 404 Not Found\r\n" 41 "Content-Length: 0\r\n" 42 "Connection: close\r\n\r\n");
45 FCGX_FPrintF(request->out,
47 "Content-Type: %s\r\n" 48 "Content-Length: %d\r\n" 52 FCGX_PutStr(buf, length, request->out);
103 :
THttpEngine(
"fastcgi",
"fastcgi interface to webserver"), fSocket(0), fDebugMode(
kFALSE), fTopName(), fThrd(0)
132 #ifndef HTTP_WITHOUT_FASTCGI 137 if ((args != 0) && (strlen(args) > 0)) {
141 while ((*args != 0) && (*args >=
'0') && (*args <=
'9')) sport.
Append(*args++);
144 while ((*args != 0) && (*args !=
'?')) args++;
161 Info(
"Create",
"Starting FastCGI server on port %s", sport.
Data() + 1);
170 Error(
"Create",
"ROOT compiled without fastcgi support");
179 #ifndef HTTP_WITHOUT_FASTCGI 183 FCGX_Request request;
185 FCGX_InitRequest(&request, engine->
GetSocket(), 0);
191 int rc = FCGX_Accept_r(&request);
193 if (rc != 0)
continue;
197 const char *inp_path = FCGX_GetParam(
"PATH_INFO", request.envp);
198 const char *inp_query = FCGX_GetParam(
"QUERY_STRING", request.envp);
199 const char *inp_method = FCGX_GetParam(
"REQUEST_METHOD", request.envp);
200 const char *inp_length = FCGX_GetParam(
"CONTENT_LENGTH", request.envp);
204 if (inp_query != 0) arg.
SetQuery(inp_query);
205 if (inp_method != 0) arg.
SetMethod(inp_method);
208 if (inp_length != 0) len = strtol(inp_length, NULL, 10);
210 void *buf =
malloc(len + 1);
211 int nread = FCGX_GetStr((
char *)buf, len, request.in);
219 for (
char **envp = request.envp; *envp != NULL; envp++) {
222 if (entry[
n] ==
'=') {
235 FCGX_FPrintF(request.out,
"Status: 200 OK\r\n" 236 "Content-type: text/html\r\n" 238 "<title>FastCGI echo</title>" 239 "<h1>FastCGI echo</h1>\n");
241 FCGX_FPrintF(request.out,
"Request %d:<br/>\n<pre>\n", count);
242 FCGX_FPrintF(request.out,
" Method : %s\n", arg.
GetMethod());
243 FCGX_FPrintF(request.out,
" PathName : %s\n", arg.
GetPathName());
244 FCGX_FPrintF(request.out,
" FileName : %s\n", arg.
GetFileName());
245 FCGX_FPrintF(request.out,
" Query : %s\n", arg.
GetQuery());
247 FCGX_FPrintF(request.out,
"</pre><p>\n");
249 FCGX_FPrintF(request.out,
"Environment:<br/>\n<pre>\n");
250 for (
char **envp = request.envp; *envp != NULL; envp++) {
251 FCGX_FPrintF(request.out,
" %s\n", *envp);
253 FCGX_FPrintF(request.out,
"</pre><p>\n");
255 FCGX_Finish_r(&request);
263 FCGX_Finish_r(&request);
271 FCGX_FPrintF(request.out, hdr.
Data());
272 }
else if (arg.
IsFile()) {
280 FCGX_FPrintF(request.out, hdr.
Data());
285 FCGX_Finish_r(&request);
const char * GetFileName() const
returns file name from request URL
virtual Bool_t Create(const char *args)
initializes fastcgi variables and start thread, which will process incoming http requests ...
void SetRequestHeader(const char *h)
set full set of request header
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
TThread * fThrd
! thread which takes requests, can be many later
This class represents a WWW compatible URL.
const char * GetPathName() const
returns path name from request URL
void SetQuery(const char *q)
set request query
const char * GetQuery() const
returns request query (string after ? in request URL)
void SetUserName(const char *n)
set name of authenticated user
Int_t fSocket
! socket used by fastcgi
void FCGX_ROOT_send_file(FCGX_Request *request, const char *fname)
THttpServer * GetServer() const
Returns pointer to THttpServer associated with engine.
void SetPostData(void *data, Long_t length, Bool_t make_copy=kFALSE)
set data, posted with the request buffer should be allocated with malloc(length+1) call...
void SetTopName(const char *topname)
set engine-specific top-name
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
TString fTopName
! name of top item
void SetPathAndFileName(const char *fullpath)
set complete path of requested http element For instance, it could be "/folder/subfolder/get.bin" Here "/folder/subfolder/" is element path and "get.bin" requested file.
TString & Append(const char *cs)
const char * GetValueFromOptions(const char *key) const
Return a value for a given key from the URL options.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Int_t Kill()
Kill this thread.
Bool_t ExecuteHttp(THttpCallArg *arg)
Execute HTTP request.
const void * GetContent() const
void SetMethod(const char *method)
set request method kind like GET or POST
Bool_t fDebugMode
! debug mode, may required for fastcgi debugging in other servers
TFastCgi()
normal constructor
void ParseOptions() const
Parse URL options into a key/value map.
static const char * GetMimeType(const char *path)
Guess mime type base on file extension.
typedef void((*Func_t)())
static char * ReadFileContent(const char *filename, Int_t &len)
Reads content of file from the disk.
virtual ~TFastCgi()
destructor
Int_t GetZipping() const
return kind of content zipping
static void * run_func(void *)
TString GetRequestHeader(const char *name)
get named field from request header
Long_t GetPostDataLength() const
return length of posted with request data
const char * GetMethod() const
returns request method like GET or POST
Bool_t IsFileRequested(const char *uri, TString &res) const
Check if file is requested, thread safe.
Bool_t CompressWithGzip()
compress reply data with gzip compression
void FillHttpHeader(TString &buf, const char *header=0)
fill HTTP header
const char * Data() const
Long_t GetContentLength() const