18 #ifndef HTTP_WITHOUT_FASTCGI
31 FCGX_FPrintF(request->out,
32 "Status: 404 Not Found\r\n"
33 "Content-Length: 0\r\n"
34 "Connection: close\r\n\r\n");
37 FCGX_FPrintF(request->out,
39 "Content-Type: %s\r\n"
40 "Content-Length: %d\r\n"
44 FCGX_PutStr(buf, length, request->out);
98 THttpEngine("fastcgi", "fastcgi interface to webserver"),
131 #ifndef HTTP_WITHOUT_FASTCGI
138 if ((args != 0) && (strlen(args) > 0)) {
142 while ((*args != 0) && (*args >=
'0') && (*args <=
'9'))
146 while ((*args != 0) && (*args !=
'?')) args++;
165 Info(
"Create",
"Starting FastCGI server on port %s", sport.
Data() + 1);
174 Error(
"Create",
"ROOT compiled without fastcgi support");
184 #ifndef HTTP_WITHOUT_FASTCGI
188 FCGX_Request request;
190 FCGX_InitRequest(&request, engine->
GetSocket(), 0);
196 int rc = FCGX_Accept_r(&request);
198 if (rc != 0)
continue;
202 const char *inp_path = FCGX_GetParam(
"PATH_INFO", request.envp);
203 const char *inp_query = FCGX_GetParam(
"QUERY_STRING", request.envp);
204 const char *inp_method = FCGX_GetParam(
"REQUEST_METHOD", request.envp);
205 const char *inp_length = FCGX_GetParam(
"CONTENT_LENGTH", request.envp);
209 if (inp_query != 0) arg.
SetQuery(inp_query);
210 if (inp_method != 0) arg.
SetMethod(inp_method);
213 if (inp_length!=0) len = strtol(inp_length,
NULL, 10);
215 void* buf =
malloc(len+1);
216 int nread = FCGX_GetStr((
char*) buf, len, request.in);
222 for (
char **envp = request.envp; *envp !=
NULL; envp++) {
225 if (entry[
n] ==
'=') { entry[
n] =
':';
break; }
236 FCGX_FPrintF(request.out,
238 "Content-type: text/html\r\n"
240 "<title>FastCGI echo</title>"
241 "<h1>FastCGI echo</h1>\n");
243 FCGX_FPrintF(request.out,
"Request %d:<br/>\n<pre>\n", count);
244 FCGX_FPrintF(request.out,
" Method : %s\n", arg.
GetMethod());
245 FCGX_FPrintF(request.out,
" PathName : %s\n", arg.
GetPathName());
246 FCGX_FPrintF(request.out,
" FileName : %s\n", arg.
GetFileName());
247 FCGX_FPrintF(request.out,
" Query : %s\n", arg.
GetQuery());
249 FCGX_FPrintF(request.out,
"</pre><p>\n");
251 FCGX_FPrintF(request.out,
"Environment:<br/>\n<pre>\n");
252 for (
char **envp = request.envp; *envp !=
NULL; envp++) {
253 FCGX_FPrintF(request.out,
" %s\n", *envp);
255 FCGX_FPrintF(request.out,
"</pre><p>\n");
257 FCGX_Finish_r(&request);
265 FCGX_Finish_r(&request);
276 FCGX_FPrintF(request.out, hdr.
Data());
277 }
else if (arg.
IsFile()) {
285 FCGX_FPrintF(request.out, hdr.
Data());
291 FCGX_Finish_r(&request);
THttpServer * GetServer() const
virtual Bool_t Create(const char *args)
initializes fastcgi variables and start thread, which will process incoming http requests ...
void SetRequestHeader(const char *h)
TThread * fThrd
name of top item
This class represents a WWW compatible URL.
Long_t GetContentLength() const
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
const char * GetPathName() const
void SetQuery(const char *q)
ClassImp(TFastCgi) TFastCgi
normal constructor
const void * GetContent() const
void SetUserName(const char *n)
void FCGX_ROOT_send_file(FCGX_Request *request, const char *fname)
const char * GetMethod() const
void SetTopName(const char *topname)
const char * Data() const
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
void SetPostData(void *data, Long_t length)
set data, posted with the request buffer should be allocated with malloc(length+1) call...
TString fTopName
debug mode, may required for fastcgi debugging in other servers
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)
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
const char * GetQuery() const
const char * GetValueFromOptions(const char *key) const
Return a value for a given key from the URL options.
Double_t length(const TVector2 &v)
const char * GetFileName() const
Bool_t IsFileRequested(const char *uri, TString &res) const
Check if file is requested, thread safe.
Int_t Kill()
Kill this thread.
Bool_t ExecuteHttp(THttpCallArg *arg)
Execute HTTP request.
void SetMethod(const char *method)
Bool_t fDebugMode
socket used by fastcgi
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.
void ParseOptions() const
Parse URL options into a key/value map.
virtual ~TFastCgi()
destructor
Long_t GetPostDataLength() const
static void * run_func(void *)
TString GetRequestHeader(const char *name)
Vc_ALWAYS_INLINE_L T *Vc_ALWAYS_INLINE_R malloc(size_t n)
Allocates memory on the Heap with alignment and padding suitable for vectorized access.
Bool_t CompressWithGzip()
compress reply data with gzip compression
void FillHttpHeader(TString &buf, const char *header=0)
fill HTTP header