Fastcgipp::Request<char>
TParent;
75 const char*
const*
env(
void)
const{
87 for(
autop:
data) {
92 void Set(
const string& name,
const string&
value) {
108 usingFastcgipp::Manager<CFastCgiThreadedRequest>::Manager;
133m_ManagerStopped(
false)
182 "specified, but this functionality is not supported");
195void (*old_sig_handler)(
int) = SIG_DFL;
196 if(handle_sigterm) {
200TManager::setupSignals();
207 autolistening =
true;
211 if( !path.empty() ) {
212 #ifdef NCBI_COMPILER_MSVC 220 if(!
m_Manager->listen(host.empty() ?
nullptr: host.c_str(), port.c_str())) {
221 ERR_POST_X(1,
"CFastCgiApplicationMT::x_RunFastCGI: cannot run as a " 222 "standalone server at: '"<< path <<
"'");
228 if(!
m_Manager->listen(path.c_str())) {
229 ERR_POST_X(1,
"CFastCgiApplicationMT::x_RunFastCGI: cannot run as a " 230 "standalone server at: '"<< path <<
"'");
237 ERR_POST_X(1,
"CFastCgiApplicationMT::x_RunFastCGI: cannot run as a " 238 "standalone server");
253 if(handle_sigterm) {
254signal(SIGTERM, old_sig_handler);
256 ERR_POST(Message <<
"Caught SIGTERM and performed graceful shutdown.");
260 _TRACE(
"CFastCgiApplicationMT::x_RunFastCGI: return (FastCGI loop finished)");
280 boolskip_stat_log =
false;
284unique_ptr<CNcbiOstream> new_stream;
286shared_ptr<CCgiContext>
context;
312&&
context->GetRequest().GetEntries().find(
"exitfastcgi")
313!=
context->GetRequest().GetEntries().end()) {
319 _TRACE(
"CFastCgiApplicationMT aborting by request");
335 _TRACE(
"CFastCgiApplicationMT calling ProcessRequest()");
339 if( !self_ref.empty() ) {
345shared_ptr<ICache> cache;
351 boolskip_process_request =
false;
353 if(cache.get() && caching_needed) {
355 context->GetResponse().out(), *cache);
358 if(!skip_process_request) {
366list<CNcbiOstream*> slist;
367orig_stream =
context->GetResponse().GetOutput();
368slist.push_back(orig_stream);
369slist.push_back(&result_copy);
371 context->GetResponse().SetOutput(new_stream.get());
389 context->GetResponse().Finalize();
392 context->GetResponse().Flush();
398 if(saved_request.get())
401}
else if(caching_needed) {
426 _TRACE(
"CFastCgiApplicationMT flushing");
427 context->GetResponse().Flush();
428 _TRACE(
"CFastCgiApplicationMT: done, status: "<< x_result);
433 context->GetResponse().SetOutput(0);
434 context->GetRequest().SetInputStream(0);
436 catch(exception& e) {
440 if(os && !os->good()) {
446 context->GetResponse().SetOutput(0);
447 context->GetRequest().SetInputStream(0);
459 string msg=
"CCgiRequestProcessorMT::ProcessRequest() failed: ";
465skip_stat_log =
true;
476 _TRACE(
"CCgiApplication::x_RunFastCGI: FINISHING(forced)");
485 _TRACE(
"CCgiRequestProcessor::x_ProcessThreadedRequest: FINISHING");
504 if(restart_code != 0) {
526 const char* s_MaxPostData_Section =
"FastCGI";
527 const char* s_MaxPostData_Name =
"MaxPostData";
528 const char* s_MaxPostData_Env =
"NCBI_CONFIG__FASTCGI__MAXPOSTDATA";
530 static Uint8s_GetMaxPostData(
void)
542 const string& s = app->
GetConfig().
Get(s_MaxPostData_Section, s_MaxPostData_Name);
580Fastcgipp::Request<char>::errorHandler();
588 const auto&
buf= environment().postBuffer();
596 const auto&
env= environment();
598 if( !
env.host.empty() )
m_Env.
Set(
"HTTP_HOST",
env.host);
599 if( !
env.origin.empty() )
m_Env.
Set(
"HTTP_ORIGIN",
env.origin);
600 if( !
env.userAgent.empty() )
m_Env.
Set(
"HTTP_USER_AGENT",
env.userAgent);
601 if( !
env.acceptContentTypes.empty() )
m_Env.
Set(
"HTTP_ACCEPT",
env.acceptContentTypes);
602 if( !
env.acceptCharsets.empty() )
m_Env.
Set(
"HTTP_ACCEPT_CHARSET",
env.acceptCharsets);
603 if( !
env.authorization.empty() )
m_Env.
Set(
"HTTP_AUTHORIZATION",
env.authorization);
604 if( !
env.referer.empty() )
m_Env.
Set(
"HTTP_REFERER",
env.referer);
605 if( !
env.contentType.empty() )
m_Env.
Set(
"CONTENT_TYPE",
env.contentType);
606 if( !
env.root.empty() )
m_Env.
Set(
"DOCUMENT_ROOT",
env.root);
607 if( !
env.scriptName.empty() )
m_Env.
Set(
"SCRIPT_NAME",
env.scriptName);
608 if( !
env.requestUri.empty() )
m_Env.
Set(
"REQUEST_URI",
env.requestUri);
616 switch(
env.requestMethod) {
618 caseFastcgipp::Http::RequestMethod::GET:
m_Env.
Set(
"REQUEST_METHOD",
"GET");
break;
619 caseFastcgipp::Http::RequestMethod::POST:
m_Env.
Set(
"REQUEST_METHOD",
"POST");
break;
620 caseFastcgipp::Http::RequestMethod::PUT:
m_Env.
Set(
"REQUEST_METHOD",
"PUT");
break;
621 caseFastcgipp::Http::RequestMethod::DELETE:
m_Env.
Set(
"REQUEST_METHOD",
"DELETE");
break;
622 caseFastcgipp::Http::RequestMethod::TRACE:
m_Env.
Set(
"REQUEST_METHOD",
"TRACE");
break;
623 caseFastcgipp::Http::RequestMethod::OPTIONS:
m_Env.
Set(
"REQUEST_METHOD",
"OPTIONS");
break;
624 caseFastcgipp::Http::RequestMethod::CONNECT:
m_Env.
Set(
"REQUEST_METHOD",
"CONNECT");
break;
626 ERR_POST_X(3,
"REQUEST_METHOD not set or not supported");
630 if(
env.serverAddress ) {
632 buf<<
env.serverAddress;
636 if(
env.remoteAddress ) {
638 buf<<
env.remoteAddress;
642 if(
env.ifModifiedSince ) {
650 for(
const auto& lang :
env.acceptLanguages) {
651 if(!languages.empty()) languages +=
", ";
654 if( !languages.empty() )
m_Env.
Set(
"HTTP_ACCEPT_LANGUAGE", languages);
658 for(
const auto& element :
env.pathInfo) {
661 m_Env.
Set(
"PATH_INFO", path_info);
663 if(!
env.cookies.empty()) {
665 for(
const auto& cookie :
env.cookies) {
666 if(!cookies.empty()) cookies +=
"; ";
670 m_Env.
Set(
"HTTP_COOKIE", cookies);
673 if(!
env.gets.empty()) {
675 for(
const auto& arg :
env.gets) {
683 for(
const auto& it :
env.others) {
Exception classes used by the NCBI CGI framework.
CCgiRequestException â.
Base class for request processors.
void Set(const string &name, const string &value)
Fastcgipp::Request< char > TParent
~CFastCgiThreadedRequest(void)
void errorHandler(void) override
bool inProcessor(void) override
const char *const * env(void) const
CFastCgiThreadedRequest(void)
void x_ParseEnv(void) const
shared_ptr< istream > m_InputStream
bool response(void) override
IWriter which can write simultaneously to the different streams.
@ fOwnWriter
Own the underlying writer.
Writer-based output stream.
std::ofstream out("events_result.xml")
main entry point for tests
DEFINE_STATIC_FAST_MUTEX(s_ManagerMutex)
void s_ScheduleFastCGIMTExit(void)
static const struct name_t names[]
static const char * str(char *buf, int n)
static CNcbiApplicationGuard InstanceGuard(void)
Singleton method.
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
bool FinishedLoadingConfig(void) const
Check if the application has finished loading config file (successfully or not).
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
void RunIdler(void)
Execute currently installed idler if any.
unsigned int GetFastCGIWatchFileTimeout(bool have_watcher) const
virtual ~CCgiRequestProcessorMT(void)
void SetOutputBroken(bool val)
unique_ptr< CCgiStatistics > m_Stat
bool GetFastCGIComplete_Request_On_Sigterm(void) const
bool CheckMemoryLimit(void)
CCgiRequestProcessorMT(CFastCgiApplicationMT &app)
bool x_RunFastCGI(int *result, unsigned int def_iter=10) override
unsigned int GetFastCGIIterations(unsigned int def_iter) const
unsigned int GetFastCGIMTMaxThreads(void) const
CAtomicCounter m_Iteration
int GetFastCGIWatchFileRestartDelay(void) const
virtual int ProcessRequest(CCgiContext &context)
Process request provided by the context. By default calls application's ProcessRequest.
static CTime GetFileModificationTime(const string &filename)
bool GetFastCGIStatLog(void) const
void SetCacheStream(CNcbiOstream &stream)
CFastCgiApplicationMT(const SBuildInfo &build_info=NCBI_SBUILDINFO_DEFAULT())
bool GetFastCGIStopIfFailed(void) const
static bool ProcessCORSRequest(const CCgiRequest &request, CCgiResponse &response)
Process cross-origin resource sharing (CORS) request.
bool x_ProcessHelpRequest(CCgiRequestProcessor &processor)
unique_ptr< TManager > m_Manager
string GetFastCGIStandaloneServer(void) const
static ERestartReason ShouldRestart(CTime &mtime, CCgiWatchFile *watcher, int delay)
unsigned int m_WatchTimeout
bool x_ProcessAdminRequest(CCgiRequestProcessor &processor)
virtual CCgiContext * CreateContext(CNcbiArguments *args=0, CNcbiEnvironment *env=0, CNcbiIstream *inp=0, CNcbiOstream *out=0, int ifd=-1, int ofd=-1)
Factory method for the Context object construction.
void x_OnEvent(CCgiRequestProcessor *pprocessor, EEvent event, int status)
virtual ICache * GetCacheStorage(void) const
unique_ptr< CNcbiResource > m_Resource
virtual int OnException(std::exception &e, CNcbiOstream &os)
unique_ptr< CCgiWatchFile > m_Watcher
virtual bool ValidateSynchronizationToken(void)
CCgiApplication & GetApp(void)
string GetRID(void) const
virtual bool IsCachingNeeded(const CCgiRequest &request) const
virtual CCgiStatistics * CreateStat()
Class factory for statistics class.
~CFastCgiApplicationMT(void)
void SaveResultToCache(const CCgiRequest &request, CNcbiIstream &is, ICache &cache)
bool x_ProcessVersionRequest(CCgiRequestProcessor &processor)
void SetContext(shared_ptr< CCgiContext > context)
void SaveRequest(const string &rid, const CCgiRequest &request, ICache &cache)
CAtomicCounter m_ErrorCounter
void FASTCGI_ScheduleExit(void) override
Schedule Fast-CGI loop to end as soon as possible, after safely finishing the currently processed req...
static CCgiApplication * Instance(void)
Singleton.
CCgiRequestProcessor & x_CreateProcessor(void)
CCgiRequest * GetSavedRequest(const string &rid, ICache &cache)
string GetSelfReferer(void) const
Get self-URL to be used as referer.
CRef< CTls< CCgiRequestProcessor > > m_Processor
void x_ProcessThreadedRequest(CFastCgiThreadedRequest &req)
bool GetFastCGIDebug(void) const
CCgiWatchFile * CreateFastCGIWatchFile(void) const
unsigned int m_MaxIterations
bool GetResultReady(void) const
bool GetResultFromCache(const CCgiRequest &request, CNcbiOstream &os, ICache &cache)
void LogRequest(void) const
bool GetFastCGIHonorExitRequest(void) const
void VerifyCgiContext(CCgiContext &context)
Check CGI context for possible problems, throw exception with HTTP status set if something is wrong.
void AddLBCookie(CCgiCookies &cookies)
static CFastCgiApplicationMT * Instance(void)
Singleton.
@ eException
An exception occured during the request processing.
@ eExitRequest
FCGI forced to exit by client's 'exitfastcgi' request.
@ eExit
No more iterations, exiting (called the very last)
@ eError
The HTTP request was processed, non-zero exit code.
@ eEndRequest
HTTP request processed, all results sent to client.
@ eExecutable
FCGI forced to exit as its modif. time has changed.
@ eWatchFile
FCGI forced to exit as its "watch file" has changed.
@ eExitOnFail
[FastCGI].StopIfFailed set, and the iteration failed
@ eSuccess
The HTTP request was processed, with zero exit code.
#define NCBI_CGI_THROW_WITH_STATUS(exception, err_code, message, status)
EStatusCode GetStatusCode(void) const
string GetStatusMessage(void) const
TNCBIAtomicValue TValue
Alias TValue for TNCBIAtomicValue.
void Set(TValue new_value) THROWS_NONE
Set atomic counter value.
TValue Add(int delta) THROWS_NONE
Atomically add value (=delta), and return new counter value.
TValue Get(void) const THROWS_NONE
Get atomic counter value.
void SetBytesWr(Int8 bytes)
CDiagContext & GetDiagContext(void)
Get diag context instance.
void SetAppState(EDiagAppState state)
Set application state.
void SetDiagRequestId(Uint8 id)
Set iteration number/request ID.
void SetProperty(const string &name, const string &value)
Add/change property.
static CRequestContext & GetRequestContext(void)
Shortcut to CDiagContextThreadData::GetThreadData().GetRequestContext()
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
void SetBytesRd(Int8 bytes)
void AddPassThroughProperty(const string &name, const string &value)
Add pass-through value if it matches a pattern from NCBI_CONTEXT_FIELDS.
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
@ eDiagAppState_RequestEnd
RE.
@ eDiagAppState_AppEnd
AE.
@ eDiagAppState_RequestBegin
RB.
@ eDiagAppState_Request
R.
#define NCBI_CATCH_ALL_X(err_subcode, message)
void Warning(CExceptionArgs_Base &args)
#define NCBI_REPORT_EXCEPTION_X(err_subcode, title, ex)
Generate a report on the exception with default error code and given subcode.
uint64_t Uint8
8-byte (64-bit) unsigned integer
static TPid GetPid(void)
Get process identifier (pid) for the current process.
virtual const string & Get(const string §ion, const string &name, TFlags flags=0) const
Get the parameter value.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Int8 NcbiStreamposToInt8(NCBI_NS_STD::char_traits< char >::pos_type stream_pos)
Convert stream position to 64-bit int.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
static Uint8 StringToUInt8_DataSize(const CTempString str, TStringToNumFlags flags=0)
Convert string that can contain "software" qualifiers to Uint8.
static string & Replace(const string &src, const string &search, const string &replace, string &dst, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
static bool SplitInTwo(const CTempString str, const CTempString delim, string &str1, string &str2, TSplitFlags flags=0)
Split a string into two pieces using the specified delimiters.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
static string URLEncode(const CTempString str, EUrlEncode flag=eUrlEnc_SkipMarkChars)
URL-encode string.
@ fAllowTrailingSpaces
Ignore trailing whitespace characters.
@ fAllowLeadingSpaces
Ignore leading whitespace characters in converted string.
@ eUrlEnc_URIQueryValue
Encode query part of an URI, arg value.
@ eUrlEnc_URIQueryName
Encode query part of an URI, arg name.
@ eUrlEnc_Path
Same as ProcessMarkChars but preserves valid path characters ('/', '.')
@ eUrlEnc_Cookie
Same as SkipMarkChars with encoded ','.
@ eCurrent
Use current time. See also CCurrentTime.
@ eGmt
GMT (Greenwich Mean Time)
unsigned int
A callback function used to compare two keys in a database.
Interfaces for a local cache of versioned binary large objects (BLOBS).
Definition of all error codes used in cgi (xcgi.lib).
const GenericPointer< typename T::ValueType > T2 value
Defines unified interface to application:
#define GetProgramName
Avoid name clash with the NCBI C Toolkit.
Defines CRequestContext class for NCBI C++ diagnostic API.
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
This class allows to add build info (date and tag) to application version.
static CS_CONTEXT * context
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4