--- parser3/src/main/pa_request.C 2020/11/10 22:42:26 1.388 +++ parser3/src/main/pa_request.C 2020/11/21 23:14:43 1.392 @@ -33,7 +33,7 @@ #include "pa_vconsole.h" #include "pa_vdate.h" -volatile const char * IDENT_PA_REQUEST_C="$Id: pa_request.C,v 1.388 2020/11/10 22:42:26 moko Exp $" IDENT_PA_REQUEST_H IDENT_PA_REQUEST_CHARSETS_H IDENT_PA_REQUEST_INFO_H IDENT_PA_VCONSOLE_H; +volatile const char * IDENT_PA_REQUEST_C="$Id: pa_request.C,v 1.392 2020/11/21 23:14:43 moko Exp $" IDENT_PA_REQUEST_H IDENT_PA_REQUEST_CHARSETS_H IDENT_PA_REQUEST_INFO_H IDENT_PA_VCONSOLE_H; // consts @@ -44,6 +44,7 @@ const char* DEFAULT_CONTENT_TYPE="text/h const uint LOOP_LIMIT=20000; const uint EXECUTE_RECOURSION_LIMIT=1000; +const uint HTTPD_TIMEOUT=4; const size_t FILE_SIZE_LIMIT=512*1024*1024; // defines for globals @@ -75,6 +76,7 @@ static const String origin_key(ORIGIN_KE int pa_loop_limit=LOOP_LIMIT; int pa_execute_recoursion_limit=EXECUTE_RECOURSION_LIMIT; +int pa_httpd_timeout=HTTPD_TIMEOUT; size_t pa_file_size_limit=FILE_SIZE_LIMIT; // defines for statics @@ -86,6 +88,7 @@ size_t pa_file_size_limit=FILE_SIZE_LIMI #define LIMITS_NAME "LIMITS" #define LOOP_LIMIT_NAME "max_loop" #define RECOURSION_LIMIT_NAME "max_recoursion" +#define HTTPD_TIMEOUT_NAME "httpd_timeout" #define FILE_SIZE_LIMIT_NAME "max_file_size" #define LOCK_WAIT_TIMEOUT_NAME "lock_wait_timeout" #define CONF_METHOD_NAME "conf" @@ -106,6 +109,7 @@ static const String prototype_name(PROTO static const String limits_name(LIMITS_NAME); static const String loop_limit_name(LOOP_LIMIT_NAME); static const String recoursion_limit_name(RECOURSION_LIMIT_NAME); +static const String httpd_timeout_name(HTTPD_TIMEOUT_NAME); static const String file_size_limit_name(FILE_SIZE_LIMIT_NAME); static const String lock_wait_timeout_name(LOCK_WAIT_TIMEOUT_NAME); @@ -121,6 +125,7 @@ static const String body_name_upper(BODY static const String content_type_name_upper(HTTP_CONTENT_TYPE_UPPER); static const String content_disposition_name_upper(CONTENT_DISPOSITION_UPPER); +static const String content_disposition_inline(CONTENT_DISPOSITION_INLINE); static const String content_disposition_attachment(CONTENT_DISPOSITION_ATTACHMENT); // defines @@ -305,6 +310,16 @@ void Request::configure_admin(VStateless throw Exception(PARSER_RUNTIME, 0, "$" MAIN_CLASS_NAME ":LIMITS." RECOURSION_LIMIT_NAME " must be int"); } + pa_httpd_timeout=HTTPD_TIMEOUT; + if(limits) + if(Value* httpd_timeout=limits->get_element(httpd_timeout_name)) { + if(httpd_timeout->is_evaluated_expr()) { + pa_httpd_timeout=httpd_timeout->as_int(); + if(pa_httpd_timeout==0) pa_httpd_timeout=INT_MAX; + } else + throw Exception(PARSER_RUNTIME, 0, "$" MAIN_CLASS_NAME ":LIMITS." HTTPD_TIMEOUT_NAME " must be int"); + } + pa_file_size_limit=FILE_SIZE_LIMIT; if(limits) if(Value* file_size_limit=limits->get_element(file_size_limit_name)) { @@ -397,7 +412,7 @@ void Request::configure() { @test log stack trace */ -void Request::core(const char* config_filespec, bool header_only) { +void Request::core(const char* config_filespec, bool header_only, const String &amain_method_name) { try { // loading config if(config_filespec) @@ -408,7 +423,8 @@ void Request::core(const char* config_fi try { // compile requested file - use_file_directly(*new String(request_info.path_translated, String::L_TAINTED), true, true /* load auto.p files */); + if(request_info.path_translated) + use_file_directly(*new String(request_info.path_translated, String::L_TAINTED), true, true /* load auto.p files */); configure(); } catch(...) { configure(); // configure anyway, useful in @unhandled_exception [say, if they would want to mail by SMTP something] @@ -416,9 +432,9 @@ void Request::core(const char* config_fi } // execute @main[] - const String* body_string=execute_method(main_class, main_method_name); + const String* body_string=amain_method_name.is_empty() ? &String::Empty : execute_method(main_class, amain_method_name); if(!body_string) - throw Exception(PARSER_RUNTIME, 0, "'" MAIN_METHOD_NAME "' method not found"); + throw Exception(PARSER_RUNTIME, 0, "'%s' method not found", amain_method_name.cstr()); // extract response body Value* body_value=response.fields().get(download_name_upper); // $response:download? @@ -672,17 +688,17 @@ const String& Request::full_disk_path(co String& result=*new String(pa_strdup(request_info.document_root)); result << relative_name; return result; - } else - if(relative_name.pos("://")!=STRING_NOT_FOUND // something like "http://xxx" + } + if(relative_name.pos("://")!=STRING_NOT_FOUND // something like "http://xxx" #ifdef WIN32 - || relative_name.pos(":")==1 // DRIVE: - || relative_name.starts_with("\\\\") // UNC1 - || relative_name.starts_with("//") // UNC2 + || relative_name.pos(":")==1 // DRIVE: + || relative_name.starts_with("\\\\") // UNC1 + || relative_name.starts_with("//") // UNC2 #endif - ) - return relative_name; - else - return relative(request_info.path_translated, relative_name); + ) + return relative_name; + + return relative(request_info.path_translated ? request_info.path_translated : request_info.document_root, relative_name); } #ifndef DOXYGEN @@ -850,12 +866,10 @@ void Request::output_result(VFile* body_ if(vfile_name) { const String& sfile_name=vfile_name->as_string(); if(sfile_name!=NONAME_DAT) { - if(as_attachment) { - VHash& hash=*new VHash(); - hash.hash().put(value_name, new VString(content_disposition_attachment)); - hash.hash().put(content_disposition_filename_name, new VString(*new String(sfile_name, String::L_HTTP_HEADER))); - response.fields().put(content_disposition_name_upper, &hash); - } + VHash& hash=*new VHash(); + hash.hash().put(value_name, new VString(as_attachment ? content_disposition_attachment : content_disposition_inline)); + hash.hash().put(content_disposition_filename_name, new VString(*new String(sfile_name, String::L_HTTP_HEADER))); + response.fields().put(content_disposition_name_upper, &hash); if(!body_file_content_type) body_file_content_type=new VString(mime_type_of(sfile_name.cstr()));