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