--- parser3/src/targets/cgi/parser3.C 2016/11/27 23:30:09 1.272 +++ parser3/src/targets/cgi/parser3.C 2016/11/29 14:35:00 1.275 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.272 2016/11/27 23:30:09 moko Exp $"; +volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.275 2016/11/29 14:35:00 moko Exp $"; #include "pa_config_includes.h" @@ -58,7 +58,10 @@ bool execution_canceled=false; // SAPI -class SAPI_Info{} SAPI_info; +class SAPI_Info { +public: + int http_response_code; +} SAPI_info = { 0 }; static void log(const char* fmt, va_list args) { bool opened=false; @@ -233,6 +236,8 @@ size_t SAPI::read_post(SAPI_Info& , char } void SAPI::add_header_attribute(SAPI_Info& , const char* dont_store_key, const char* dont_store_value) { + if(strcasecmp(dont_store_key, HTTP_STATUS)==0) + SAPI_info.http_response_code=atoi(dont_store_value); if( cgi && (!request || !request->console.was_used()) ) printf("%s: %s\n", capitalize(dont_store_key), dont_store_value); } @@ -556,6 +561,10 @@ static void call_real_parser_handler__su if(parser_exception) throw Exception(parser_exception); } + +#define REAL_PARSER_HANDLER call_real_parser_handler__supress_system_exception +#else +#define REAL_PARSER_HANDLER real_parser_handler #endif static void usage(const char* program) { @@ -679,13 +688,7 @@ int main(int argc, char *argv[]) { bool header_only=request_method && strcasecmp(request_method, "HEAD")==0; try { // global try -#ifdef PA_SUPPRESS_SYSTEM_EXCEPTION - call_real_parser_handler__supress_system_exception( -#else - real_parser_handler( -#endif - filespec_to_process, - request_method, header_only); + REAL_PARSER_HANDLER(filespec_to_process, request_method, header_only); } catch(const Exception& e) { // global problem // don't allocate anything on pool here: // possible pool' exception not catch-ed now @@ -719,5 +722,5 @@ int main(int argc, char *argv[]) { #ifdef PA_DEBUG_CGI_ENTRY_EXIT log("main: successful return"); #endif - return 0; + return SAPI_info.http_response_code < 100 ? SAPI_info.http_response_code : 0; }