37 const char *
GetWSKind()
const override {
return "longpoll"; }
49#ifndef HTTP_WITHOUT_FASTCGI
60 FCGX_FPrintF(request->out,
61 "Status: 404 Not Found\r\n"
62 "Content-Length: 0\r\n"
63 "Connection: close\r\n\r\n");
66 FCGX_FPrintF(request->out,
68 "Content-Type: %s\r\n"
69 "Content-Length: %d\r\n"
73 FCGX_PutStr(buf.c_str(), buf.length(), request->out);
83 const char *inp_path = FCGX_GetParam(
"PATH_INFO", request->envp);
84 if (!inp_path) inp_path = FCGX_GetParam(
"SCRIPT_FILENAME", request->envp);
85 const char *inp_query = FCGX_GetParam(
"QUERY_STRING", request->envp);
86 const char *inp_method = FCGX_GetParam(
"REQUEST_METHOD", request->envp);
87 const char *inp_length = FCGX_GetParam(
"CONTENT_LENGTH", request->envp);
89 auto arg = std::make_shared<TFastCgiCallArg>(can_postpone);
91 arg->SetPathAndFileName(inp_path);
93 arg->SetQuery(inp_query);
95 arg->SetMethod(inp_method);
100 len = strtol(inp_length,
nullptr, 10);
104 int nread = FCGX_GetStr((
char *)buf.data(),
len, request->in);
106 arg->SetPostData(std::move(buf));
110 for (
char **envp = request->envp; *envp !=
nullptr; envp++) {
113 if (entry[
n] ==
'=') {
120 arg->SetRequestHeader(header);
122 TString username = arg->GetRequestHeader(
"REMOTE_USER");
123 if ((username.
Length() > 0) && (arg->GetRequestHeader(
"AUTH_TYPE").Length() > 0))
124 arg->SetUserName(username);
127 FCGX_FPrintF(request->out,
"Status: 200 OK\r\n"
128 "Content-type: text/html\r\n"
130 "<title>FastCGI echo</title>"
131 "<h1>FastCGI echo</h1>\n");
133 FCGX_FPrintF(request->out,
"Request %d:<br/>\n<pre>\n", count);
134 FCGX_FPrintF(request->out,
" Method : %s\n", arg->GetMethod());
135 FCGX_FPrintF(request->out,
" PathName : %s\n", arg->GetPathName());
136 FCGX_FPrintF(request->out,
" FileName : %s\n", arg->GetFileName());
137 FCGX_FPrintF(request->out,
" Query : %s\n", arg->GetQuery());
138 FCGX_FPrintF(request->out,
" PostData : %ld\n", arg->GetPostDataLength());
139 FCGX_FPrintF(request->out,
"</pre><p>\n");
141 FCGX_FPrintF(request->out,
"Environment:<br/>\n<pre>\n");
142 for (
char **envp = request->envp; *envp !=
nullptr; envp++)
143 FCGX_FPrintF(request->out,
" %s\n", *envp);
144 FCGX_FPrintF(request->out,
"</pre><p>\n");
157 std::string hdr = arg->FillHttpHeader(
"Status:");
158 FCGX_FPrintF(request->out, hdr.c_str());
159 }
else if (arg->IsFile()) {
165 arg->CompressWithGzip();
167 std::string hdr = arg->FillHttpHeader(
"Status:");
168 FCGX_FPrintF(request->out, hdr.c_str());
170 FCGX_PutStr((
const char *)arg->GetContent(), (
int)arg->GetContentLength(), request->out);
176 std::condition_variable cond;
178 std::unique_ptr<FCGX_Request> arg;
181 auto worker_func = [engine, &cond, &
m, &arg, &nwaiting]() {
185 std::unique_ptr<FCGX_Request> request;
187 bool can_postpone =
false;
190 std::unique_lock<std::mutex> lk(
m);
194 can_postpone = (nwaiting > 5);
195 std::swap(arg, request);
201 FCGX_Finish_r(request.get());
208 std::vector<std::thread> workers;
209 for (
int n=0;
n< nthrds; ++
n)
210 workers.emplace_back(worker_func);
213 auto request = std::make_unique<FCGX_Request>();
215 FCGX_InitRequest(request.get(), engine->
GetSocket(), 0);
217 int rc = FCGX_Accept_r(request.get());
223 std::lock_guard<std::mutex> lk(
m);
225 std::swap(request, arg);
234 FCGX_Finish_r(request.get());
242 for (
auto & thrd : workers)
252 FCGX_Request request;
254 FCGX_InitRequest(&request, engine->
GetSocket(), 0);
258 int rc = FCGX_Accept_r(&request);
265 FCGX_Finish_r(&request);
315 :
THttpEngine(
"fastcgi",
"fastcgi interface to webserver")
345#ifndef HTTP_WITHOUT_FASTCGI
351 if ((args != 0) && (strlen(args) > 0)) {
355 while ((*args != 0) && (*args >=
'0') && (*args <=
'9'))
359 while ((*args != 0) && (*args !=
'?'))
382 Info(
"Create",
"Starting FastCGI server on port %s", sport.
Data() + 1);
395 Error(
"Create",
"ROOT compiled without fastcgi support");
void process_request(TFastCgi *engine, FCGX_Request *request, bool can_postpone)
void run_single_thread(TFastCgi *engine)
void run_multi_threads(TFastCgi *engine, Int_t nthrds)
void FCGX_ROOT_send_file(FCGX_Request *request, const char *fname)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
const char * GetWSPlatform() const override
provide WS platform
const char * GetWSKind() const override
provide WS kind
Bool_t CanPostpone() const override
All FastCGI requests should be immediately replied to get slot for next.
TFastCgiCallArg(bool can_postpone)
THttpEngine implementation, based on fastcgi package.
TFastCgi()
normal constructor
Bool_t IsTerminating() const
TString fTopName
! name of top item
std::unique_ptr< std::thread > fThrd
! thread which takes requests, can be many later
Bool_t fDebugMode
! debug mode, may required for fastcgi debugging in other servers
const char * GetTopName() const
virtual ~TFastCgi()
destructor
Bool_t Create(const char *args) override
create engine data
Int_t fSocket
! socket used by fastcgi
Bool_t IsDebugMode() const
Bool_t fTerminating
! set when http server wants to terminate all engines
Contains arguments for single HTTP call.
Abstract class for implementing http protocol for THttpServer.
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.
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.
Int_t GetIntValueFromOptions(const char *key) const
Return a value for a given key from the URL options as an Int_t, a missing key returns -1.
void ParseOptions() const
Parse URL options into a key/value map.
Bool_t HasOption(const char *key) const
Returns true if the given key appears in the URL options list.