--- parser3/src/main/pa_request.C 2001/03/24 19:12:20 1.78 +++ parser3/src/main/pa_request.C 2001/03/27 15:37:52 1.83 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_request.C,v 1.78 2001/03/24 19:12:20 paf Exp $ + $Id: pa_request.C,v 1.83 2001/03/27 15:37:52 paf Exp $ */ #include "pa_config_includes.h" @@ -17,6 +17,7 @@ #include "pa_vclass.h" #include "_root.h" #include "_table.h" +#include "_file.h" #include "pa_globals.h" #include "pa_vint.h" #include "pa_vmframe.h" @@ -26,6 +27,12 @@ /// $limits.post_max_size default 10M const size_t MAX_POST_SIZE_DEFAULT=10*0x400*400; +/// 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"; + // Request::Request(Pool& apool, Info& ainfo, @@ -50,7 +57,8 @@ Request::Request(Pool& apool, classes().put(*root_class_name, &ROOT); // table class classes().put(*table_class_name, table_class); - + // file class + classes().put(*file_class_name, file_class); // env class classes().put(*env_class_name, &env); // form class @@ -136,14 +144,17 @@ void Request::core(const char *root_auto /* /document/root */ char *file_spec= (char *)malloc(strlen(info.path_translated)+strlen(AUTO_FILE_NAME)+1); - strcpy(file_spec, info.document_root); + size_t document_root_size=strlen(info.document_root); + if(info.document_root[document_root_size-1]=='/') + document_root_size--; + memcpy(file_spec, info.document_root, document_root_size); /* /requested/file.html */ char *branches=(char *)malloc(strlen(info.path_translated)+1); - strcpy(branches, info.path_translated+strlen(info.document_root)); + strcpy(branches, info.path_translated+document_root_size); char *next=branches; + char *append_here=file_spec+document_root_size; - char *append_here=file_spec+strlen(file_spec); size_t slash_auto_p_size=strlen("/" AUTO_FILE_NAME); while(true) { char *step=lsplit(&next, '/'); @@ -173,9 +184,7 @@ void Request::core(const char *root_auto Value *defaults=main_class->get_element(*defaults_name); // value must be allocated on request's pool for that pool used on // meaning constructing @see attributed_meaning_to_string - default_content_type=defaults? - defaults->get_element(*content_type_name) - :NEW VString(*NEW String(pool(), "text/html")); + default_content_type=defaults?defaults->get_element(*content_type_name):0; if(Value *element=main_class->get_element(*html_typo_name)) if(VTable *vtable=element->get_vtable()) pool().set_tag(&vtable->table()); @@ -187,6 +196,9 @@ void Request::core(const char *root_auto 0, "'"MAIN_METHOD_NAME"' method not found"); + // post-process + // todo + // extract response body Value *body_value=static_cast( response.fields().get(*body_name)); @@ -342,7 +354,7 @@ void Request::core(const char *root_auto // future $response:content-type response.fields().put(*content_type_name, - NEW VString(*NEW String(pool(), "text/plain"))); + NEW VString(*NEW String(pool(), UNHANDLED_EXCEPTION_CONTENT_TYPE))); // future $response:body body_string=NEW String(pool(), buf); } @@ -433,7 +445,9 @@ void Request::output_result(const String cookie.output_result(); // set default content-type - response.fields().put_dont_replace(*content_type_name, default_content_type); + response.fields().put_dont_replace(*content_type_name, + default_content_type?default_content_type + :NEW VString(*NEW String(pool(), DEFAULT_CONTENT_TYPE))); // prepare header: $response:fields without :body response.fields().for_each(add_header_attribute, /*excluding*/ body_name);