--- parser3/src/main/pa_request.C 2002/12/02 10:07:39 1.243 +++ parser3/src/main/pa_request.C 2003/01/30 14:59:44 1.245.2.3 @@ -1,11 +1,11 @@ /** @file Parser: request class main part. @see compile.C and execute.C. - Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_REQUEST_C="$Date: 2002/12/02 10:07:39 $"; +static const char* IDENT_REQUEST_C="$Date: 2003/01/30 14:59:44 $"; #include "pa_sapi.h" #include "pa_common.h" @@ -22,6 +22,12 @@ static const char* IDENT_REQUEST_C="$Dat #include "pa_charset.h" #include "pa_charsets.h" +// defines + +#define MAIN_METHOD_NAME "main" + +// consts + const char *POST_PROCESS_METHOD_NAME="postprocess"; const char *UNHANDLED_EXCEPTION_METHOD_NAME="unhandled_exception"; @@ -32,6 +38,11 @@ const char *UNHANDLED_EXCEPTION_CONTENT_ const char *DEFAULT_CONTENT_TYPE="text/html"; const char *ORIGINS_CONTENT_TYPE="text/plain"; +// globals + +StringPtr main_method_name(MAIN_METHOD_NAME), + + // op.C VClass& VClassMAIN_create(Pool& pool); // op.C @@ -42,7 +53,6 @@ Request::Request(Pool& apool, Info& ainfo, uchar adefault_lang, bool status_allowed) : Pooled(apool), - main_method_name(apool, MAIN_METHOD_NAME), stack(apool), main_class(VClassMAIN_create(apool)), env(apool), @@ -56,8 +66,8 @@ Request::Request(Pool& apool, fclasses(apool), fdefault_lang(adefault_lang), flang(adefault_lang), info(ainfo), + charsets(UTF8_charset, UTF8_charset, UTF8_charset), post_data(0), post_size(0), - used_files(apool), configure_admin_done(false), default_content_type(0), mime_types(0), @@ -72,8 +82,8 @@ Request::Request(Pool& apool, finterrupted(false) { // default charsets - pool().set_source_charset(*utf8_charset); - pool().set_client_charset(*utf8_charset); + pool().set_source_charset(UTF8_charset); + pool().set_client_charset(UTF8_charset); // maybe expire old caches cache_managers->maybe_expire(); @@ -286,7 +296,12 @@ gettimeofday(&mt[2],NULL); // extract response body Value *body_value=static_cast( - response.fields().get(*body_name)); + response.fields().get(*download_name)); + bool as_attachment=body_value!=0; + if(!body_value) + body_value=static_cast( + response.fields().get(*body_name)); + if(body_value) // there is some $response:body body_file=body_value->as_vfile(); else if(lorigins_mode) @@ -299,7 +314,7 @@ gettimeofday(&mt[3],NULL); #endif // OK. write out the result - output_result(*body_file, header_only); + output_result(*body_file, header_only, as_attachment); #ifdef RESOURCES_DEBUG //measure:after output_result @@ -437,20 +452,20 @@ t[9]-t[3] const VFile *body_file=body_vstring.as_vfile(); // ERROR. write it out - output_result(*body_file, header_only); + output_result(*body_file, header_only, false); } catch(const Exception& ) { /*re*/throw; } } } -VStateless_class *Request::use_file(VStateless_class& aclass, - const String& file_name, bool ignore_class_path, +VStateless_classPtr Request::use_file(VStateless_class& aclass, + ConstStringPtr file_name, bool ignore_class_path, bool fail_on_read_problem, bool fail_on_file_absence) { // cyclic dependence check if(used_files.get(file_name)) return 0; - used_files.put(file_name, (Hash::Val *)true); + used_files.put(file_name, true); const String *file_spec; if(ignore_class_path) // ignore_class_path? @@ -496,7 +511,7 @@ VStateless_class *Request::use_file(VSta } -VStateless_class *Request::use_buf(VStateless_class& aclass, +VStateless_classPtr Request::use_buf(VStateless_class& aclass, const char *source, const String& filespec, const char *filespec_cstr) { // temporary zero @conf so to maybe-replace it in compiled code @@ -548,6 +563,7 @@ static void add_header_attribute(const H void *info) { Request& r=*static_cast(info); if(aattribute==BODY_NAME + || aattribute==DOWNLOAD_NAME || aattribute==CHARSET_NAME) return; @@ -559,7 +575,7 @@ static void add_header_attribute(const H attributed_meaning_to_string(lmeaning, String::UL_HTTP_HEADER, false) .cstr(String::UL_UNSPECIFIED)); } -void Request::output_result(const VFile& body_file, bool header_only) { +void Request::output_result(const VFile& body_file, bool header_only, bool as_attachment) { // header: cookies cookie.output_result(); @@ -581,7 +597,8 @@ void Request::output_result(const VFile& if(vfile_name->string()!=NONAME_DAT) { VHash& vhash=*NEW VHash(pool()); Hash& hash=vhash.hash(0); - hash.put(*value_name, NEW VString(*content_disposition_value)); + if(as_attachment) + hash.put(*value_name, NEW VString(*content_disposition_value)); hash.put(*content_disposition_filename_name, vfile_name); response.fields().put(*content_disposition_name, &vhash); }