--- parser3/src/main/pa_request.C 2017/05/03 17:53:19 1.375 +++ parser3/src/main/pa_request.C 2020/10/14 00:07:42 1.381 @@ -33,15 +33,12 @@ #include "pa_vconsole.h" #include "pa_vdate.h" -volatile const char * IDENT_PA_REQUEST_C="$Id: pa_request.C,v 1.375 2017/05/03 17:53:19 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.381 2020/10/14 00:07:42 moko Exp $" IDENT_PA_REQUEST_H IDENT_PA_REQUEST_CHARSETS_H IDENT_PA_REQUEST_INFO_H IDENT_PA_VCONSOLE_H; // consts #define UNHANDLED_EXCEPTION_METHOD_NAME "unhandled_exception" -/// content type of exception response, when no @MAIN:exception handler defined -const char* UNHANDLED_EXCEPTION_CONTENT_TYPE="text/plain"; - /// content type of response when no $MAIN:defaults.content-type defined const char* DEFAULT_CONTENT_TYPE="text/html"; @@ -539,34 +536,27 @@ void Request::core(const char* config_fi } } - if(!body_string) { // couldn't report an error beautifully? - // doing that ugly - - // future $response:content-type - response.fields().put(content_type_name_upper, new VString(*new String(UNHANDLED_EXCEPTION_CONTENT_TYPE))); - // future $response:body - body_string=new String(exception_cstr); - } - - VString body_vstring(*body_string); - VFile* body_file=body_vstring.as_vfile(flang, &charsets); - // conditionally log it Value* vhandled=details.vhash.hash().get(exception_handled_part_name); if(!vhandled || !vhandled->as_bool()) { SAPI::log(sapi_info, "%s", exception_cstr); } - // ERROR. write it out - output_result(body_file, header_only, false); + if(body_string) { // could report an error beautifully? + VString body_vstring(*body_string); + VFile* body_file=body_vstring.as_vfile(flang, &charsets); + // write it out the error + output_result(body_file, header_only, false); + } else { + // doing that ugly + SAPI::send_error(sapi_info, exception_cstr, !strcmp(e.type(), "file.missing") ? "404" : "500"); + } } catch(const Exception& e) { // exception in unhandled exception Request::Exception_details details=get_details(e); const char* exception_cstr=get_exception_cstr(e, details); - // unconditionally log the beast - SAPI::log(sapi_info, "%s", exception_cstr); - - throw Exception(0, 0, "in %s", exception_cstr); + // unconditionally log the beast in exception handler + throw Exception(0, 0, "Unhandled exception in %s", exception_cstr); } } } @@ -634,7 +624,7 @@ void Request::use_file(const String& fil static String use("USE"); try { static VHash* voptions=new VHash(); - if(const Method *method=main_class.get_element_method(use_method_name)){ + if(const Method *method=main_class.get_method(use_method_name)){ Value *params[]={new VString(file_name), voptions}; voptions->hash().put(origin_key, new VString(*use_filespec)); @@ -777,7 +767,7 @@ static void parse_range(const String* s, static void output_pieces(Request& r, bool header_only, const String& filename, size_t content_length, Value& date, bool add_last_modified) { SAPI::add_header_attribute(r.sapi_info, "accept-ranges", "bytes"); - const size_t BUFSIZE = 10*0x400; + const size_t BUFSIZE = 128*0x400; char buf[BUFSIZE]; const char *range = SAPI::Env::get(r.sapi_info, "HTTP_RANGE"); size_t offset=0; @@ -830,10 +820,8 @@ static void output_pieces(Request& r, bo size_t to_read = 0; size_t size = 0; do{ - to_read = part_length