Annotation of parser3/src/main/pa_request.C, revision 1.195
1.54 paf 1: /** @file
1.55 paf 2: Parser: request class main part. @see compile.C and execute.C.
3:
1.193 paf 4: Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.194 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.55 paf 6:
1.195 ! paf 7: $Id: pa_request.C,v 1.194 2002/02/08 08:30:16 paf Exp $
1.1 paf 8: */
9:
1.69 paf 10: #include "pa_sapi.h"
1.53 paf 11: #include "pa_common.h"
1.1 paf 12: #include "pa_request.h"
1.3 paf 13: #include "pa_wwrapper.h"
14: #include "pa_vclass.h"
1.31 paf 15: #include "pa_globals.h"
1.30 paf 16: #include "pa_vint.h"
1.112 paf 17: #include "pa_vmethod_frame.h"
1.32 paf 18: #include "pa_types.h"
1.78 paf 19: #include "pa_vtable.h"
1.90 paf 20: #include "pa_vfile.h"
1.147 parser 21: #include "pa_dictionary.h"
1.186 paf 22: #include "pa_charsets.h"
23: #include "pa_charset.h"
1.159 parser 24:
1.82 paf 25: /// content type of exception response, when no @MAIN:exception handler defined
26: const char *UNHANDLED_EXCEPTION_CONTENT_TYPE="text/plain";
27:
28: /// content type of response when no $MAIN:defaults.content-type defined
29: const char *DEFAULT_CONTENT_TYPE="text/html";
1.144 parser 30: const char *ORIGINS_CONTENT_TYPE="text/plain";
1.82 paf 31:
1.123 paf 32: Methoded *MOP_create(Pool&);
1.195 ! paf 33: // op.C
! 34: VHash& exception2vhash(Pool& pool, const Exception& e);
1.123 paf 35:
1.160 parser 36: static void load_charset(const Hash::Key& akey, Hash::Val *avalue,
1.186 paf 37: void *) {
1.190 paf 38: charsets->load_charset(akey, static_cast<Value *>(avalue)->as_string());
1.157 parser 39: }
40:
41: //
42: Request::Request(Pool& apool,
43: Info& ainfo,
1.182 paf 44: uchar adefault_lang,
1.179 paf 45: bool status_allowed) : Pooled(apool),
1.157 parser 46: stack(apool),
47: OP(*MOP_create(apool)),
48: env(apool),
1.175 paf 49: status(apool),
1.157 parser 50: form(apool),
51: math(apool),
52: request(apool, *this),
53: response(apool),
54: cookie(apool),
55: fclasses(apool),
56: fdefault_lang(adefault_lang), flang(adefault_lang),
57: info(ainfo),
58: post_data(0), post_size(0),
59: used_files(apool),
60: default_content_type(0),
61: mime_types(0),
62: main_class(0),
1.191 paf 63: fconnection(0),
1.157 parser 64: classes_conf(apool),
1.171 parser 65: anti_endless_execute_recoursion(0),
66: trace(apool)
1.183 paf 67: #ifdef RESOURCES_DEBUG
68: ,sql_connect_time(0),sql_request_time(0)
69: #endif
1.157 parser 70: {
1.186 paf 71: // default charsets
72: pool().set_source_charset(*utf8_charset);
73: pool().set_client_charset(*utf8_charset);
74:
1.178 paf 75: // maybe expire old caches
76: cache_managers->maybe_expire();
77:
1.157 parser 78: /// directly used
79: // operators
80: OP.register_directly_used(*this);
81: // classes:
82: // table, file, random, mail, image, ...
83: methoded_array->register_directly_used(*this);
84:
85: /// methodless
86: // env class
87: classes().put(*NEW String(pool(), ENV_CLASS_NAME), &env);
1.175 paf 88: // status class
1.179 paf 89: if(status_allowed)
90: classes().put(*NEW String(pool(), STATUS_CLASS_NAME), &status);
1.157 parser 91: // request class
92: classes().put(*NEW String(pool(), REQUEST_CLASS_NAME), &request);
93: // cookie class
94: classes().put(*NEW String(pool(), COOKIE_CLASS_NAME), &cookie);
95:
96: /// methoded
97: // response class
98: classes().put(response.get_class()->name(), &response);
99:
100: /// bases used
101: // form class
102: classes().put(form.get_class()->base()->name(), &form);
103: // math class
104: classes().put(math.get_class()->base()->name(), &math);
1.117 paf 105: }
1.192 paf 106:
107: Request::~Request() {
108: #ifdef XML
109: // if for some strange reason xml generic errors failed to be reported, free them up
110: if(const char *xml_generic_errors=xmlGenericErrors()) {
111: SAPI::log(pool(), "warning: unreported xmlGenericErrors: %s", xml_generic_errors);
112: free((void *)xml_generic_errors);
113: }
114: #endif
115: }
116:
1.150 parser 117:
1.64 paf 118: /**
119: load MAIN class, execute @main.
120: MAIN class consists of all the auto.p files we'd manage to find
121: plus
122: the file user requested us to process
123: all located classes become children of one another,
124: composing class we name 'MAIN'
1.180 paf 125:
126: @test log stack trace
127:
1.64 paf 128: */
1.153 parser 129: void Request::core(
130: const char *root_config_filespec, bool root_config_fail_on_read_problem,
131: const char *site_config_filespec, bool site_config_fail_on_read_problem,
1.62 paf 132: bool header_only) {
1.183 paf 133:
134: #ifdef RESOURCES_DEBUG
135: //measures
136: struct timeval mt[10];
137: //measure:before all
138: gettimeofday(&mt[0],NULL);
139: #endif
1.169 parser 140: try {
1.29 paf 141: char *auto_filespec=(char *)malloc(MAX_STRING);
142:
1.153 parser 143: // loading root config
144: if(root_config_filespec) {
1.77 paf 145: String& filespec=*NEW String(pool());
1.153 parser 146: filespec.APPEND_CLEAN(root_config_filespec, 0, "root_config", 0);
1.29 paf 147: main_class=use_file(
1.148 parser 148: filespec,
1.153 parser 149: true/*ignore class_path*/, root_config_fail_on_read_problem,
1.37 paf 150: main_class_name, main_class);
1.29 paf 151: }
1.186 paf 152: // charsets must only be specified in root config
153: // so that users would not interfere
1.164 parser 154: if(main_class) {
155: /* $MAIN:CHARSETS[
156: $.charsetname1[/full/path/to/charset/file.cfg]
157: ...
158: ]
159: */
160: if(Value *vcharsets=main_class->get_element(*charsets_name)) {
1.172 parser 161: if(Hash *charsets=vcharsets->get_hash(0))
1.186 paf 162: charsets->for_each(load_charset);
1.164 parser 163: else
1.169 parser 164: throw Exception(0, 0,
1.164 parser 165: &vcharsets->name(),
166: "must be hash");
167: }
168: }
1.124 paf 169: // configure root options
1.72 paf 170: // until someone with less privileges have overriden them
1.129 paf 171: OP.configure_admin(*this);
1.124 paf 172: methoded_array->configure_admin(*this);
1.72 paf 173:
1.153 parser 174: // loading site config
175: if(site_config_filespec) {
1.77 paf 176: String& filespec=*NEW String(pool());
1.153 parser 177: filespec.APPEND_CLEAN(site_config_filespec, 0, "site_config", 0);
1.37 paf 178: main_class=use_file(
1.148 parser 179: filespec,
1.153 parser 180: true/*ignore class_path*/, site_config_fail_on_read_problem,
1.37 paf 181: main_class_name, main_class);
1.29 paf 182: }
1.8 paf 183:
1.72 paf 184: // loading auto.p files from document_root/..
185: // to the one beside requested file.
186: // all assigned bases from upper dir
187: {
1.115 paf 188: const char *after=info.path_translated;
189: size_t drlen=strlen(info.document_root);
190: if(memcmp(after, info.document_root, drlen)==0) {
191: after+=drlen;
192: if(after[-1]=='/')
193: --after;
194: }
195:
1.152 parser 196: int step=0;
1.115 paf 197: while(const char *before=strchr(after, '/')) {
1.152 parser 198: String& sfile_spec=*NEW String(pool());
1.115 paf 199: if(after!=info.path_translated) {
1.152 parser 200: sfile_spec.APPEND_CLEAN(
201: info.path_translated, before-info.path_translated,
202: "path-translated-scanned", step++);
203: sfile_spec << "/" AUTO_FILE_NAME;
204:
205: main_class=use_file(sfile_spec,
206: true/*ignore class_path*/, false/*ignore read problem*/,
207: main_class_name, main_class);
1.115 paf 208: }
209: after=before+1;
1.72 paf 210: }
211: }
1.34 paf 212:
1.125 paf 213: // compile requested file
1.77 paf 214: String& spath_translated=*NEW String(pool());
1.136 parser 215: spath_translated.APPEND_TAINTED(info.path_translated, 0, "user-request", 0);
1.148 parser 216: main_class=use_file(spath_translated,
217: true/*ignore class_path*/, true/*don't ignore read problem*/,
1.72 paf 218: main_class_name, main_class);
1.7 paf 219:
1.124 paf 220: // configure not-root=user options
1.129 paf 221: OP.configure_user(*this);
1.124 paf 222: methoded_array->configure_user(*this);
223:
1.85 paf 224: // $MAIN:MIME-TYPES
225: if(Value *element=main_class->get_element(*mime_types_name))
226: if(Table *table=element->get_table())
227: mime_types=table;
1.102 paf 228:
1.124 paf 229: // filling form fields
1.153 parser 230: form.fill_fields_and_tables(*this);
1.102 paf 231:
1.124 paf 232: // filling cookies
233: cookie.fill_fields(*this);
1.25 paf 234:
1.183 paf 235: #ifdef RESOURCES_DEBUG
236: //measure:after compile
237: gettimeofday(&mt[1],NULL);
238: #endif
1.25 paf 239: // execute @main[]
1.189 paf 240: const String *body_string=execute_virtual_method(*main_class, *main_method_name);
1.41 paf 241: if(!body_string)
1.169 parser 242: throw Exception(0,0,
1.145 parser 243: 0,
244: "'"MAIN_METHOD_NAME"' method not found");
1.79 paf 245:
1.183 paf 246: #ifdef RESOURCES_DEBUG
247: //measure:after main
248: gettimeofday(&mt[2],NULL);
249: #endif
250:
1.91 paf 251: VString body_vstring_before_post_process(*body_string);
252: VString *body_vstring_after_post_process=&body_vstring_before_post_process;
1.119 paf 253: // @postprocess
1.91 paf 254: if(Value *value=main_class->get_element(*post_process_method_name))
255: if(Junction *junction=value->get_junction())
256: if(const Method *method=junction->method) {
257: // preparing to pass parameters to
1.119 paf 258: // @postprocess[data]
1.146 parser 259: VMethodFrame frame(pool(), value->name(), *junction);
1.91 paf 260: frame.set_self(*main_class);
261:
262: frame.store_param(method->name,
263: &body_vstring_before_post_process);
264: body_vstring_after_post_process=
1.188 paf 265: NEW VString(execute_method(frame, *method));
1.91 paf 266: }
1.90 paf 267:
1.144 parser 268: bool origins_mode=main_class->get_element(*origins_mode_name)!=0;
269:
270: const VFile *body_file=body_vstring_after_post_process->as_vfile(
271: String::UL_UNSPECIFIED, origins_mode);
1.41 paf 272:
1.45 paf 273: // extract response body
274: Value *body_value=static_cast<Value *>(
275: response.fields().get(*body_name));
1.119 paf 276: if(body_value) // there is some $response.body
1.90 paf 277: body_file=body_value->as_vfile();
1.144 parser 278: else if(origins_mode)
279: response.fields().put(*content_type_name,
280: NEW VString(*NEW String(pool(), ORIGINS_CONTENT_TYPE)));
1.45 paf 281:
1.183 paf 282: #ifdef RESOURCES_DEBUG
283: //measure:after postprocess
284: gettimeofday(&mt[3],NULL);
285: #endif
286:
1.45 paf 287: // OK. write out the result
1.90 paf 288: output_result(*body_file, header_only);
1.183 paf 289:
290: #ifdef RESOURCES_DEBUG
291: //measure:after output_result
292: gettimeofday(&mt[9],NULL);
293: t[9]=mt[9].tv_sec+mt[9].tv_usec/1000000.0;
294:
295: double t[10];
296: for(int i=0;i<10;i++)
297: t[i]=mt[i].tv_sec+mt[i].tv_usec/1000000.0;
298: //measure:log2 compile,main,postprocess,output
299: SAPI::log(pool(), "rmeasure: %s,%.2f,%.2f,%.2f %.2f,%.2f %.2f",
300: info.uri,
301: t[1]-t[0],
302: t[2]-t[1],
303: t[3]-t[2],
304: sql_connect_time,sql_request_time,
305: t[9]-t[3]
306: );
307: #endif
1.171 parser 308: } catch(const Exception& e) { // request handling problem
1.76 paf 309: // we're returning not result, but error explanation
1.169 parser 310: try {
1.76 paf 311: // log the beast
312: const String *problem_source=e.problem_source();
1.114 paf 313: if(problem_source && problem_source->size())
1.76 paf 314: SAPI::log(pool(),
315: #ifndef NO_STRING_ORIGIN
1.180 paf 316: ORIGIN_FILE_LINE_FORMAT": "
1.76 paf 317: #endif
318: "'%s' %s [%s %s]",
319: #ifndef NO_STRING_ORIGIN
320: problem_source->origin().file?problem_source->origin().file:"global",
321: problem_source->origin().line,
322: #endif
1.173 paf 323: problem_source->cstr(),
1.76 paf 324: e.comment(),
1.173 paf 325: e.type()?e.type()->cstr():"-",
326: e.code()?e.code()->cstr():"-"
1.76 paf 327: );
328: else
329: SAPI::log(pool(),
330: "%s [%s %s]",
331: e.comment(),
1.173 paf 332: e.type()?e.type()->cstr():"-",
333: e.code()?e.code()->cstr():"-"
1.180 paf 334: );
1.171 parser 335:
1.43 paf 336: // reset language to default
337: flang=fdefault_lang;
338:
339: // reset response
340: response.fields().clear();
341:
342: // this is what we'd return in $response:body
1.41 paf 343: const String *body_string=0;
1.43 paf 344:
1.30 paf 345: if(main_class) { // we've managed to end up with some main_class
346: // maybe we'd be lucky enough as to report an error
347: // in a gracefull way...
1.195 ! paf 348: if(Value *value=main_class->get_element(*unhandled_exception_method_name))
1.30 paf 349: if(Junction *junction=value->get_junction())
350: if(const Method *method=junction->method) {
1.169 parser 351: // preparing to pass parameters to
1.171 parser 352: // @exception[origin;source;comment;type;code;stack]
1.146 parser 353: VMethodFrame frame(pool(), value->name(), *junction);
1.38 paf 354: frame.set_self(*main_class);
1.30 paf 355:
1.195 ! paf 356: frame.store_param(method->name, &exception2vhash(pool(), e));
1.171 parser 357: // $stack[^table::set{name origin}]
358: Array& stack_trace_columns=*NEW Array(pool());
359: stack_trace_columns+=NEW String(pool(), "name");
1.195 ! paf 360: stack_trace_columns+=NEW String(pool(), "file");
! 361: stack_trace_columns+=NEW String(pool(), "lineno");
1.171 parser 362: Table& stack_trace=*NEW Table(pool(), 0, &stack_trace_columns);
363: Array_iter tracei(trace);
364: while(tracei.has_next()) {
365: Array& row=*NEW Array(pool());
366:
367: const String *name=(const String *)tracei.next();
368: row+=name; // name column
369: #ifndef NO_STRING_ORIGIN
370: const Origin& origin=name->origin();
371: if(origin.file) {
1.195 ! paf 372: row+=NEW String(pool(), origin.file, 0, true); // file column
! 373: char *buf=(char *)malloc(MAX_NUMBER);
! 374: size_t buf_size=snprintf(buf, MAX_NUMBER, "%d", 1+origin.line);
! 375: row+=NEW String(pool(), buf, buf_size, true); // line column
1.171 parser 376: }
377: #endif
378: stack_trace+=&row;
379: }
380: frame.store_param(method->name,
381: NEW VTable(pool(), &stack_trace));
382:
1.43 paf 383: // future $response:body=
1.171 parser 384: // execute ^exception[origin;source;comment;type;code;stack]
1.188 paf 385: body_string=&execute_method(frame, *method);
1.30 paf 386: }
387: }
388:
1.41 paf 389: if(!body_string) { // couldn't report an error beautifully?
390: // doing that ugly
391:
392: // make up result: $origin $source $comment $type $code
393: char *buf=(char *)malloc(MAX_STRING);
1.30 paf 394: size_t printed=0;
395: const String *problem_source=e.problem_source();
396: if(problem_source) {
1.16 paf 397: #ifndef NO_STRING_ORIGIN
1.30 paf 398: const Origin& origin=problem_source->origin();
399: if(origin.file)
1.180 paf 400: printed+=snprintf(buf+printed, MAX_STRING-printed,
401: ORIGIN_FILE_LINE_FORMAT": ",
402: origin.file, 1+origin.line
403: );
1.28 paf 404: #endif
1.41 paf 405: printed+=snprintf(buf+printed, MAX_STRING-printed, "'%s' ",
1.173 paf 406: problem_source->cstr());
1.30 paf 407: }
1.41 paf 408: printed+=snprintf(buf+printed, MAX_STRING-printed, "%s",
1.30 paf 409: e.comment());
410: const String *type=e.type();
411: if(type) {
1.41 paf 412: printed+=snprintf(buf+printed, MAX_STRING-printed, " type: %s",
1.173 paf 413: type->cstr());
1.30 paf 414: const String *code=e.code();
415: if(code)
1.41 paf 416: printed+=snprintf(buf+printed, MAX_STRING-printed, ", code: %s",
1.173 paf 417: code->cstr());
1.30 paf 418: }
1.43 paf 419:
420: // future $response:content-type
1.49 paf 421: response.fields().put(*content_type_name,
1.82 paf 422: NEW VString(*NEW String(pool(), UNHANDLED_EXCEPTION_CONTENT_TYPE)));
1.43 paf 423: // future $response:body
1.44 paf 424: body_string=NEW String(pool(), buf);
1.30 paf 425: }
1.41 paf 426:
1.144 parser 427: VString body_vstring(*body_string);
1.90 paf 428: const VFile *body_file=body_vstring.as_vfile();
429:
1.45 paf 430: // ERROR. write it out
1.90 paf 431: output_result(*body_file, header_only);
1.170 parser 432: } catch(const Exception& ) {
1.169 parser 433: /*re*/throw;
1.3 paf 434: }
1.1 paf 435: }
436: }
437:
1.148 parser 438: VStateless_class *Request::use_file(const String& file_name,
439: bool ignore_class_path, bool fail_on_read_problem,
1.26 paf 440: const String *name,
441: VStateless_class *base_class) {
1.73 paf 442: // cyclic dependence check
1.148 parser 443: if(used_files.get(file_name))
1.73 paf 444: return base_class;
1.148 parser 445: used_files.put(file_name, (Hash::Val *)true);
1.73 paf 446:
1.148 parser 447: const String *file_spec;
1.153 parser 448: if(ignore_class_path) // ignore_class_path?
1.148 parser 449: file_spec=&file_name;
1.153 parser 450: else if(file_name.first_char()=='/') //absolute path, no need to scan MAIN:CLASS_PATH?
451: file_spec=&absolute(file_name);
452: else {
453: file_spec=0;
454: if(main_class)
455: if(Value *element=main_class->get_element(*class_path_name)) {
456: if(element->is_string()) {
1.187 paf 457: file_spec=file_readable(absolute(element->as_string()), file_name); // found at class_path?
1.153 parser 458: } else if(Table *table=element->get_table()) {
459: int size=table->size();
460: for(int i=size; i--; ) {
461: const String& path=*static_cast<Array *>(table->get(i))->get_string(0);
1.187 paf 462: if(file_spec=file_readable(absolute(path), file_name))
1.153 parser 463: break; // found along class_path
1.148 parser 464: }
1.153 parser 465: } else
1.169 parser 466: throw Exception(0, 0,
1.153 parser 467: &element->name(),
468: "must be string or table");
469: if(!file_spec)
1.169 parser 470: throw Exception(0, 0,
1.153 parser 471: &file_name,
472: "not found along " MAIN_CLASS_NAME ":" CLASS_PATH_NAME);
473: }
474: if(!file_spec)
1.169 parser 475: throw Exception(0, 0,
1.153 parser 476: &file_name,
477: "usage failed - no " MAIN_CLASS_NAME ":" CLASS_PATH_NAME " were specified");
1.148 parser 478: }
1.73 paf 479:
1.148 parser 480: char *source=file_read_text(pool(), *file_spec, fail_on_read_problem);
1.3 paf 481: if(!source)
1.12 paf 482: return base_class;
1.3 paf 483:
1.148 parser 484: return use_buf(source, file_spec->cstr(), 0/*new class*/, name, base_class);
1.16 paf 485: }
486:
1.67 paf 487: VStateless_class *Request::use_buf(const char *source, const char *file,
1.26 paf 488: VStateless_class *aclass, const String *name,
489: VStateless_class *base_class) {
1.5 paf 490: // compile loaded class
1.26 paf 491: VStateless_class& cclass=COMPILE(source, aclass, name, base_class, file);
1.1 paf 492:
1.4 paf 493: // locate and execute possible @auto[] static method
1.143 parser 494: execute_nonvirtual_method(cclass, *auto_method_name, false /*no result needed*/);
1.16 paf 495: return &cclass;
1.19 paf 496: }
497:
1.77 paf 498: const String& Request::relative(const char *apath, const String& relative_name) {
499: int lpath_buf_size=strlen(apath)+1;
500: char *lpath=(char *)malloc(lpath_buf_size);
501: memcpy(lpath, apath, lpath_buf_size);
1.120 paf 502: if(!rsplit(lpath, '/'))
503: strcpy(lpath, ".");
1.77 paf 504: String& result=*NEW String(pool(), lpath);
1.104 paf 505: result << "/" << relative_name;
1.19 paf 506: return result;
507: }
508:
1.77 paf 509: const String& Request::absolute(const String& relative_name) {
510: char *relative_name_cstr=relative_name.cstr();
511: if(relative_name_cstr[0]=='/') {
512: String& result=*NEW String(pool(), info.document_root);
1.104 paf 513: result << relative_name;
1.19 paf 514: return result;
515: } else
1.77 paf 516: return relative(info.path_translated, relative_name);
1.1 paf 517: }
1.45 paf 518:
1.101 paf 519: static void add_header_attribute(const Hash::Key& aattribute, Hash::Val *ameaning,
520: void *info) {
1.178 paf 521: Request& r=*static_cast<Request *>(info);
1.184 paf 522: if(aattribute==BODY_NAME
523: || aattribute==CHARSET_NAME)
1.101 paf 524: return;
525:
526: Value& lmeaning=*static_cast<Value *>(ameaning);
527: Pool& pool=lmeaning.pool();
528:
529: SAPI::add_header_attribute(pool,
1.173 paf 530: aattribute.cstr(),
1.101 paf 531: attributed_meaning_to_string(lmeaning, String::UL_HTTP_HEADER).cstr());
532: }
1.90 paf 533: void Request::output_result(const VFile& body_file, bool header_only) {
1.51 paf 534: // header: cookies
535: cookie.output_result();
536:
1.90 paf 537: // set content-type
538: if(String *body_file_content_type=static_cast<String *>(
539: body_file.fields().get(*vfile_mime_type_name))) {
540: // body file content type
541: response.fields().put(*content_type_name, body_file_content_type);
542: } else {
543: // default content type
544: response.fields().put_dont_replace(*content_type_name,
545: default_content_type?default_content_type
546: :NEW VString(*NEW String(pool(), DEFAULT_CONTENT_TYPE)));
1.92 paf 547: }
548:
549: // content-disposition
1.111 paf 550: if(VString *vfile_name=static_cast<VString *>(body_file.fields().get(*name_name)))
551: if(vfile_name->string()!=NONAME_DAT) {
552: VHash& vhash=*NEW VHash(pool());
1.174 paf 553: vhash.hash(0).put(*content_disposition_filename_name, vfile_name);
1.111 paf 554: response.fields().put(*content_disposition_name, &vhash);
555: }
1.49 paf 556:
1.62 paf 557: // prepare header: $response:fields without :body
1.178 paf 558: response.fields().for_each(add_header_attribute, this);
1.50 paf 559:
1.185 paf 560: // transcode
1.184 paf 561: const void *client_body;
562: size_t client_content_length;
1.186 paf 563: Charset::transcode(pool(),
564: pool().get_source_charset(), body_file.value_ptr(), body_file.value_size(),
565: pool().get_client_charset(), client_body, client_content_length
1.184 paf 566: );
1.50 paf 567:
1.62 paf 568: // prepare header: content-length
1.184 paf 569: if(client_content_length) { // useful for redirecting [header "location: http://..."]
1.65 paf 570: char content_length_cstr[MAX_NUMBER];
1.184 paf 571: snprintf(content_length_cstr, MAX_NUMBER, "%u", client_content_length);
1.69 paf 572: SAPI::add_header_attribute(pool(), "content-length", content_length_cstr);
1.65 paf 573: }
1.62 paf 574:
575: // send header
1.69 paf 576: SAPI::send_header(pool());
1.71 paf 577:
1.62 paf 578: // send body
579: if(!header_only)
1.184 paf 580: SAPI::send_body(pool(), client_body, client_content_length);
1.50 paf 581: }
1.104 paf 582:
583: const String& Request::mime_type_of(const char *user_file_name_cstr) {
584: if(mime_types)
585: if(const char *cext=strrchr(user_file_name_cstr, '.')) {
586: String sext(pool(), ++cext);
587: if(mime_types->locate(0, sext))
588: if(const String *result=mime_types->item(1))
589: return *result;
590: else
1.169 parser 591: throw Exception(0, 0,
1.104 paf 592: mime_types->origin_string(),
593: "MIME-TYPE table column elements must not be empty");
594: }
595: return *NEW String(pool(), "application/octet-stream");
1.133 parser 596: }
E-mail: