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