Annotation of parser3/src/main/pa_request.C, revision 1.109
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.55 paf 5:
1.14 paf 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.9 paf 7:
1.109 ! paf 8: $Id: pa_request.C,v 1.108 2001/04/09 14:01:58 paf Exp $
1.1 paf 9: */
10:
1.70 paf 11: #include "pa_config_includes.h"
1.19 paf 12:
1.96 paf 13: #include <locale.h>
14:
1.69 paf 15: #include "pa_sapi.h"
1.53 paf 16: #include "pa_common.h"
1.1 paf 17: #include "pa_request.h"
1.3 paf 18: #include "pa_wwrapper.h"
19: #include "pa_vclass.h"
1.100 paf 20: #include "_op.h"
1.17 paf 21: #include "_table.h"
1.82 paf 22: #include "_file.h"
1.31 paf 23: #include "pa_globals.h"
1.30 paf 24: #include "pa_vint.h"
25: #include "pa_vmframe.h"
1.32 paf 26: #include "pa_types.h"
1.78 paf 27: #include "pa_vtable.h"
1.89 paf 28: #include "_random.h"
1.90 paf 29: #include "pa_vfile.h"
1.101 paf 30: #include "_mail.h"
1.106 paf 31: #include "_exec.h"
1.109 ! paf 32: #include "_image.h"
1.3 paf 33:
1.109 ! paf 34: /// $LIMITS.post_max_size default 10M
1.72 paf 35: const size_t MAX_POST_SIZE_DEFAULT=10*0x400*400;
36:
1.82 paf 37: /// content type of exception response, when no @MAIN:exception handler defined
38: const char *UNHANDLED_EXCEPTION_CONTENT_TYPE="text/plain";
39:
40: /// content type of response when no $MAIN:defaults.content-type defined
41: const char *DEFAULT_CONTENT_TYPE="text/html";
42:
1.72 paf 43: //
1.28 paf 44: Request::Request(Pool& apool,
1.33 paf 45: Info& ainfo,
1.43 paf 46: String::Untaint_lang adefault_lang) : Pooled(apool),
1.3 paf 47: stack(apool),
1.100 paf 48: OP(apool),
1.41 paf 49: env(apool),
50: form(apool),
51: request(apool, *this),
52: response(apool),
1.51 paf 53: cookie(apool),
1.3 paf 54: fclasses(apool),
1.43 paf 55: fdefault_lang(adefault_lang), flang(adefault_lang),
56: info(ainfo),
1.105 paf 57: post_data(0), post_size(0),
1.85 paf 58: used_files(apool),
1.74 paf 59: default_content_type(0),
1.94 paf 60: mime_types(0),
1.103 paf 61: connection(0), protocol2library(0),
62: mail(0)
1.3 paf 63: {
1.27 paf 64: // root superclass,
1.3 paf 65: // parent of all classes,
66: // operators holder
1.100 paf 67: initialize_op_class(pool(), OP);
68: classes().put(*op_class_name, &OP);
1.27 paf 69: // table class
70: classes().put(*table_class_name, table_class);
1.82 paf 71: // file class
72: classes().put(*file_class_name, file_class);
1.89 paf 73: // random class
74: classes().put(*random_class_name, random_class);
1.3 paf 75: // env class
1.41 paf 76: classes().put(*env_class_name, &env);
1.27 paf 77: // form class
1.41 paf 78: classes().put(*form_class_name, &form);
1.40 paf 79: // request class
1.41 paf 80: classes().put(*request_class_name, &request);
81: // response class
82: classes().put(*response_class_name, &response);
1.51 paf 83: // cookie class
84: classes().put(*cookie_class_name, &cookie);
1.101 paf 85: // mail class
1.106 paf 86: classes().put(*mail_class_name, mail_class);
1.109 ! paf 87: // image class
! 88: classes().put(*image_class_name, image_class);
1.45 paf 89: }
90:
1.64 paf 91: /**
92: load MAIN class, execute @main.
93: MAIN class consists of all the auto.p files we'd manage to find
94: plus
95: the file user requested us to process
96: all located classes become children of one another,
97: composing class we name 'MAIN'
1.96 paf 98:
1.102 paf 99: @test get read of setlocale
1.64 paf 100: */
1.63 paf 101: void Request::core(const char *root_auto_path, bool root_auto_fail,
102: const char *site_auto_path, bool site_auto_fail,
1.62 paf 103: bool header_only) {
1.29 paf 104: VStateless_class *main_class=0;
1.41 paf 105: bool need_rethrow=false; Exception rethrow_me;
1.3 paf 106: TRY {
1.29 paf 107: char *auto_filespec=(char *)malloc(MAX_STRING);
108:
1.63 paf 109: // loading root auto.p
110: if(root_auto_path) {
1.77 paf 111: String& filespec=*NEW String(pool());
1.88 paf 112: filespec.APPEND_CLEAN(root_auto_path, 0, "root_auto", 0);
1.77 paf 113: filespec.APPEND_CONST("/" AUTO_FILE_NAME);
1.29 paf 114: main_class=use_file(
1.77 paf 115: filespec, root_auto_fail,
1.37 paf 116: main_class_name, main_class);
1.29 paf 117: }
118:
1.85 paf 119: // $MAIN:LIMITS hash used here,
1.72 paf 120: // until someone with less privileges have overriden them
1.78 paf 121: {
122: Value *limits=main_class?main_class->get_element(*limits_name):0;
1.106 paf 123: if(info.method && StrEqNc(info.method, "post", true)) {
1.105 paf 124: // $limits.post_max_size default 10M
125: Value *element=limits?limits->get_element(*post_max_size_name):0;
126: size_t value=element?(size_t)element->as_double():0;
127: size_t post_max_size=value?value:MAX_POST_SIZE_DEFAULT;
128:
129: size_t post_size=max(0, min(info.content_length, post_max_size));
130: if(post_size) {
1.106 paf 131: // read POST data
1.105 paf 132: post_data=(char *)malloc(post_size);
133: size_t read_size=SAPI::read_post(pool(), post_data, post_size);
134: if(read_size!=post_size)
135: THROW(0, 0,
136: 0,
137: "post_size(%d)!=read_size(%d)",
138: post_size, read_size);
139: }
140: }
141:
142: form.fill_fields(*this);
1.78 paf 143: }
1.72 paf 144:
1.78 paf 145: // filling cookies
1.72 paf 146: cookie.fill_fields(*this);
147:
1.64 paf 148: // loading site auto.p
1.63 paf 149: if(site_auto_path) {
1.77 paf 150: String& filespec=*NEW String(pool());
1.88 paf 151: filespec.APPEND_CLEAN(site_auto_path, 0, "site_auto", 0);
1.77 paf 152: filespec.APPEND_CONST("/" AUTO_FILE_NAME);
1.37 paf 153: main_class=use_file(
1.77 paf 154: filespec, site_auto_fail,
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: {
162: /* /document/root */
1.77 paf 163: char *file_spec=
1.72 paf 164: (char *)malloc(strlen(info.path_translated)+strlen(AUTO_FILE_NAME)+1);
1.83 paf 165: size_t document_root_size=strlen(info.document_root);
166: if(info.document_root[document_root_size-1]=='/')
167: document_root_size--;
168: memcpy(file_spec, info.document_root, document_root_size);
1.72 paf 169:
170: /* /requested/file.html */
171: char *branches=(char *)malloc(strlen(info.path_translated)+1);
1.83 paf 172: strcpy(branches, info.path_translated+document_root_size);
1.72 paf 173: char *next=branches;
1.83 paf 174: char *append_here=file_spec+document_root_size;
1.72 paf 175:
176: size_t slash_auto_p_size=strlen("/" AUTO_FILE_NAME);
177: while(true) {
178: char *step=lsplit(&next, '/');
179: if(next) { // not 'file.html' part
180: size_t step_size=strlen(step);
181: memcpy(append_here, step, step_size);
182: append_here+=step_size;
183: memcpy(append_here, "/" AUTO_FILE_NAME, slash_auto_p_size+1);
184: append_here++/* / */;
185:
1.77 paf 186: String& sfile_spec=*NEW String(pool());
1.88 paf 187: sfile_spec.APPEND_CLEAN(file_spec, 0, "scanned", 0);
1.77 paf 188: main_class=use_file(sfile_spec, false/*ignore read problem*/,
1.72 paf 189: main_class_name, main_class);
190: } else
191: break;
192: }
193: }
1.34 paf 194:
1.72 paf 195: // compiling requested file
1.77 paf 196: String& spath_translated=*NEW String(pool());
1.88 paf 197: spath_translated.APPEND_CLEAN(info.path_translated, 0, "user-request", 0);
1.77 paf 198: main_class=use_file(spath_translated, true/*don't ignore read problem*/,
1.72 paf 199: main_class_name, main_class);
1.7 paf 200:
1.85 paf 201: // $MAIN:DEFAULTS
1.78 paf 202: Value *defaults=main_class->get_element(*defaults_name);
1.75 paf 203: // value must be allocated on request's pool for that pool used on
204: // meaning constructing @see attributed_meaning_to_string
1.80 paf 205: default_content_type=defaults?defaults->get_element(*content_type_name):0;
1.78 paf 206: if(Value *element=main_class->get_element(*html_typo_name))
1.87 paf 207: if(Table *table=element->get_table())
208: pool().set_tag(table);
1.95 paf 209:
210: // $MAIN:SQL.drivers
211: if(Value *sql=main_class->get_element(*main_sql_name))
212: if(Value *element=sql->get_element(*main_sql_drivers_name))
213: protocol2library=element->get_table();
1.85 paf 214:
215: // $MAIN:MIME-TYPES
216: if(Value *element=main_class->get_element(*mime_types_name))
217: if(Table *table=element->get_table())
218: mime_types=table;
1.96 paf 219:
220: // $MAIN:LOCALE.ctype[Russian_Russia.1251]
221: /*
222: #define LC_ALL 0
223: #define LC_COLLATE 1
224: #define LC_CTYPE 2
225: #define LC_MONETARY 3
226: #define LC_NUMERIC 4
227: #define LC_TIME 5
228: */
229: if(Value *locale=main_class->get_element(*locale_name))
230: if(Value *element=locale->get_element(*locale_ctype_name)) {
231: const String& name=element->as_string();
232: if(!setlocale(LC_CTYPE, name.cstr()))
233: THROW(0, 0,
234: &name,
1.97 paf 235: "locale is invalid");
1.96 paf 236: }
1.102 paf 237:
238: // $MAIN:MAIL[$SMTP[mail.design.ru]]
239: if(Value *mail_element=main_class->get_element(*mail_name))
240: if(!(mail=mail_element->get_hash()))
241: THROW(0, 0,
242: 0,
243: "$MAIN:MAIL is not hash");
244:
1.25 paf 245:
246: // execute @main[]
1.41 paf 247: const String *body_string=execute_method(*main_class, *main_method_name);
248: if(!body_string)
1.25 paf 249: THROW(0,0,
250: 0,
251: "'"MAIN_METHOD_NAME"' method not found");
1.79 paf 252:
1.91 paf 253: VString body_vstring_before_post_process(*body_string);
254: VString *body_vstring_after_post_process=&body_vstring_before_post_process;
255:
256: // post-process
257: if(Value *value=main_class->get_element(*post_process_method_name))
258: if(Junction *junction=value->get_junction())
259: if(const Method *method=junction->method) {
260: // preparing to pass parameters to
261: // @post-process[data]
1.98 paf 262: VMethodFrame frame(pool(), *junction, false);
1.91 paf 263: frame.set_self(*main_class);
264:
265: frame.store_param(method->name,
266: &body_vstring_before_post_process);
267: body_vstring_after_post_process=
268: NEW VString(*execute_method(frame, *method));
269: }
1.90 paf 270:
1.91 paf 271: const VFile *body_file=body_vstring_after_post_process->as_vfile();
1.41 paf 272:
1.45 paf 273: // extract response body
274: Value *body_value=static_cast<Value *>(
275: response.fields().get(*body_name));
276: if(body_value) // there is some $request.body
1.90 paf 277: body_file=body_value->as_vfile();
1.45 paf 278:
279: // OK. write out the result
1.90 paf 280: output_result(*body_file, header_only);
1.3 paf 281: }
1.76 paf 282: CATCH(e) { // request handling problem
283: // we're returning not result, but error explanation
1.30 paf 284: TRY {
1.76 paf 285: // log the beast
286: const String *problem_source=e.problem_source();
287: if(problem_source)
288: SAPI::log(pool(),
289: #ifndef NO_STRING_ORIGIN
290: "%s(%d): "
291: #endif
292: "'%s' %s [%s %s]",
293: #ifndef NO_STRING_ORIGIN
294: problem_source->origin().file?problem_source->origin().file:"global",
295: problem_source->origin().line,
296: #endif
1.99 paf 297: problem_source->cstr(String::UL_AS_IS),
1.76 paf 298: e.comment(),
1.99 paf 299: e.type()?e.type()->cstr(String::UL_AS_IS):"-",
300: e.code()?e.code()->cstr(String::UL_AS_IS):"-"
1.76 paf 301: );
302: else
303: SAPI::log(pool(),
304: "%s [%s %s]",
305: e.comment(),
1.99 paf 306: e.type()?e.type()->cstr(String::UL_AS_IS):"-",
307: e.code()?e.code()->cstr(String::UL_AS_IS):"-"
1.76 paf 308: );
1.43 paf 309:
310: // reset language to default
311: flang=fdefault_lang;
312:
313: // reset response
314: response.fields().clear();
315:
316: // this is what we'd return in $response:body
1.41 paf 317: const String *body_string=0;
1.43 paf 318:
1.30 paf 319: if(main_class) { // we've managed to end up with some main_class
320: // maybe we'd be lucky enough as to report an error
321: // in a gracefull way...
322: if(Value *value=main_class->get_element(*exception_method_name))
323: if(Junction *junction=value->get_junction())
324: if(const Method *method=junction->method) {
325: // preparing to pass parameters to
326: // @exception[origin;source;comment;type;code]
1.98 paf 327: VMethodFrame frame(pool(), *junction, false);
1.38 paf 328: frame.set_self(*main_class);
1.30 paf 329:
330: const String *problem_source=e.problem_source();
331: // origin
1.38 paf 332: Value *origin_value=0;
1.30 paf 333: #ifndef NO_STRING_ORIGIN
1.38 paf 334: if(problem_source) {
335: const Origin& origin=problem_source->origin();
336: if(origin.file) {
337: char *buf=(char *)malloc(MAX_STRING);
1.106 paf 338: size_t buf_size=snprintf(buf, MAX_STRING, "%s(%d):",
1.38 paf 339: origin.file, 1+origin.line);
1.44 paf 340: String *origin_file_line=NEW String(pool(),
1.106 paf 341: buf, buf_size, true);
1.38 paf 342: origin_value=NEW VString(*origin_file_line);
343: }
1.30 paf 344: }
345: #endif
1.91 paf 346: frame.store_param(method->name,
1.38 paf 347: origin_value?origin_value:NEW VUnknown(pool()));
1.28 paf 348:
1.30 paf 349: // source
1.38 paf 350: Value *source_value=0;
1.43 paf 351: if(problem_source) {
1.47 paf 352: String& problem_source_copy=*NEW String(pool());
353: problem_source_copy.append(*problem_source,
354: flang, true);
1.43 paf 355: source_value=NEW VString(problem_source_copy);
356: }
1.91 paf 357: frame.store_param(method->name,
1.38 paf 358: source_value?source_value:NEW VUnknown(pool()));
1.30 paf 359:
360: // comment
1.44 paf 361: String *comment_value=NEW String(pool(),
1.106 paf 362: e.comment(), 0, true);
1.91 paf 363: frame.store_param(method->name,
1.30 paf 364: NEW VString(*comment_value));
365:
366: // type
367: Value *type_value;
1.43 paf 368: if(e.type()) {
1.47 paf 369: String& type_copy=*NEW String(pool());
370: type_value=NEW VString(type_copy.append(*e.type(),
371: flang, true));
1.43 paf 372: } else
1.30 paf 373: type_value=NEW VUnknown(pool());
1.91 paf 374: frame.store_param(method->name, type_value);
1.30 paf 375:
376: // code
377: Value *code_value;
1.43 paf 378: if(e.code()) {
1.47 paf 379: String& code_copy=*NEW String(pool());
380: code_value=NEW VString(code_copy.append(*e.code(),
381: flang, true));
1.43 paf 382: } else
1.30 paf 383: code_value=NEW VUnknown(pool());
1.91 paf 384: frame.store_param(method->name, code_value);
1.30 paf 385:
1.43 paf 386: // future $response:body=
387: // execute ^exception[origin;source;comment;type;code]
388: body_string=execute_method(frame, *method);
1.30 paf 389: }
390: }
391:
1.41 paf 392: if(!body_string) { // couldn't report an error beautifully?
393: // doing that ugly
394:
395: // make up result: $origin $source $comment $type $code
396: char *buf=(char *)malloc(MAX_STRING);
1.30 paf 397: size_t printed=0;
398: const String *problem_source=e.problem_source();
399: if(problem_source) {
1.16 paf 400: #ifndef NO_STRING_ORIGIN
1.30 paf 401: const Origin& origin=problem_source->origin();
402: if(origin.file)
1.41 paf 403: printed+=snprintf(buf+printed, MAX_STRING-printed, "%s(%d): ",
1.30 paf 404: origin.file, 1+origin.line);
1.28 paf 405: #endif
1.41 paf 406: printed+=snprintf(buf+printed, MAX_STRING-printed, "'%s' ",
1.99 paf 407: problem_source->cstr(String::UL_AS_IS));
1.30 paf 408: }
1.41 paf 409: printed+=snprintf(buf+printed, MAX_STRING-printed, "%s",
1.30 paf 410: e.comment());
411: const String *type=e.type();
412: if(type) {
1.41 paf 413: printed+=snprintf(buf+printed, MAX_STRING-printed, " type: %s",
1.99 paf 414: type->cstr(String::UL_AS_IS));
1.30 paf 415: const String *code=e.code();
416: if(code)
1.41 paf 417: printed+=snprintf(buf+printed, MAX_STRING-printed, ", code: %s",
1.99 paf 418: code->cstr(String::UL_AS_IS));
1.30 paf 419: }
1.43 paf 420:
421: // future $response:content-type
1.49 paf 422: response.fields().put(*content_type_name,
1.82 paf 423: NEW VString(*NEW String(pool(), UNHANDLED_EXCEPTION_CONTENT_TYPE)));
1.43 paf 424: // future $response:body
1.44 paf 425: body_string=NEW String(pool(), buf);
1.30 paf 426: }
1.41 paf 427:
1.90 paf 428: const VString body_vstring(*body_string);
429: const VFile *body_file=body_vstring.as_vfile();
430:
1.45 paf 431: // ERROR. write it out
1.90 paf 432: output_result(*body_file, header_only);
1.3 paf 433: }
1.30 paf 434: CATCH(e) {
1.41 paf 435: // exception in request exception handler
436: // remember to rethrow it
437: rethrow_me=e; need_rethrow=true;
1.1 paf 438: }
1.30 paf 439: END_CATCH
1.1 paf 440: }
1.41 paf 441: END_CATCH // do not use pool() after this point - no exception handler set
442: // any throw() would try to use zero exception() pointer
443:
1.91 paf 444: if(need_rethrow) // were there an exception for us to rethrow?
1.62 paf 445: THROW(rethrow_me.type(), rethrow_me.code(),
1.41 paf 446: rethrow_me.problem_source(),
447: rethrow_me.comment());
1.1 paf 448: }
449:
1.77 paf 450: VStateless_class *Request::use_file(const String& file_spec, bool fail_on_read_problem,
1.26 paf 451: const String *name,
452: VStateless_class *base_class) {
1.73 paf 453: // cyclic dependence check
1.77 paf 454: if(used_files.get(file_spec))
1.73 paf 455: return base_class;
1.77 paf 456: used_files.put(file_spec, (Hash::Val *)true);
1.73 paf 457:
458:
1.77 paf 459: char *source=file_read_text(pool(), file_spec, fail_on_read_problem);
1.3 paf 460: if(!source)
1.12 paf 461: return base_class;
1.3 paf 462:
1.77 paf 463: return use_buf(source, file_spec.cstr(), 0/*new class*/, name, base_class);
1.16 paf 464: }
465:
1.67 paf 466: VStateless_class *Request::use_buf(const char *source, const char *file,
1.26 paf 467: VStateless_class *aclass, const String *name,
468: VStateless_class *base_class) {
1.5 paf 469: // compile loaded class
1.26 paf 470: VStateless_class& cclass=COMPILE(source, aclass, name, base_class, file);
1.1 paf 471:
1.4 paf 472: // locate and execute possible @auto[] static method
1.25 paf 473: execute_method(cclass, *auto_method_name, false /*no result needed*/);
1.16 paf 474: return &cclass;
1.20 paf 475: }
476:
1.52 paf 477: /**
478: - fail_if_junction(true, junction = fail
479: - fail_if_junction(false, not junction = fail
480: */
1.62 paf 481: void Request::fail_if_junction_(bool is, Value& value,
482: const String& method_name, const char *msg) {
1.20 paf 483:
484: if((value.get_junction()!=0) ^ !is)
485: THROW(0, 0,
486: &method_name,
487: msg);
1.19 paf 488: }
489:
1.77 paf 490: const String& Request::relative(const char *apath, const String& relative_name) {
491: int lpath_buf_size=strlen(apath)+1;
492: char *lpath=(char *)malloc(lpath_buf_size);
493: memcpy(lpath, apath, lpath_buf_size);
494: rsplit(lpath, '/');
495: String& result=*NEW String(pool(), lpath);
1.104 paf 496: result << "/" << relative_name;
1.19 paf 497: return result;
498: }
499:
1.77 paf 500: const String& Request::absolute(const String& relative_name) {
501: char *relative_name_cstr=relative_name.cstr();
502: if(relative_name_cstr[0]=='/') {
503: String& result=*NEW String(pool(), info.document_root);
1.104 paf 504: result << relative_name;
1.19 paf 505: return result;
506: } else
1.77 paf 507: return relative(info.path_translated, relative_name);
1.1 paf 508: }
1.45 paf 509:
1.101 paf 510: static void add_header_attribute(const Hash::Key& aattribute, Hash::Val *ameaning,
511: void *info) {
512: String *attribute_to_exclude=static_cast<String *>(info);
513: if(aattribute==*attribute_to_exclude)
514: return;
515:
516: Value& lmeaning=*static_cast<Value *>(ameaning);
517: Pool& pool=lmeaning.pool();
518:
519: String attribute(pool);
520: SAPI::add_header_attribute(pool,
521: attribute.append(aattribute, String::UL_HTTP_HEADER, true).cstr(),
522: attributed_meaning_to_string(lmeaning, String::UL_HTTP_HEADER).cstr());
523: }
1.90 paf 524: void Request::output_result(const VFile& body_file, bool header_only) {
1.51 paf 525: // header: cookies
526: cookie.output_result();
527:
1.90 paf 528: // set content-type
529: if(String *body_file_content_type=static_cast<String *>(
530: body_file.fields().get(*vfile_mime_type_name))) {
531: // body file content type
532: response.fields().put(*content_type_name, body_file_content_type);
533: } else {
534: // default content type
535: response.fields().put_dont_replace(*content_type_name,
536: default_content_type?default_content_type
537: :NEW VString(*NEW String(pool(), DEFAULT_CONTENT_TYPE)));
1.92 paf 538: }
539:
540: // content-disposition
541: if(VString *vfile_name=static_cast<VString *>(body_file.fields().get(*name_name))) {
542: VHash& vhash=*NEW VHash(pool());
543: vhash.hash().put(*content_disposition_filename_name, vfile_name);
544: response.fields().put(*content_disposition_name, &vhash);
1.90 paf 545: }
1.49 paf 546:
1.62 paf 547: // prepare header: $response:fields without :body
1.73 paf 548: response.fields().for_each(add_header_attribute, /*excluding*/ body_name);
1.50 paf 549:
1.62 paf 550: // prepare...
1.90 paf 551: const void *body=body_file.value_ptr();
552: size_t content_length=body_file.value_size();
1.50 paf 553:
1.62 paf 554: // prepare header: content-length
1.65 paf 555: if(content_length) { // useful for redirecting [header "location: http://..."]
556: char content_length_cstr[MAX_NUMBER];
1.108 paf 557: snprintf(content_length_cstr, MAX_NUMBER, "%u", content_length);
1.69 paf 558: SAPI::add_header_attribute(pool(), "content-length", content_length_cstr);
1.65 paf 559: }
1.62 paf 560:
561: // send header
1.69 paf 562: SAPI::send_header(pool());
1.71 paf 563:
1.62 paf 564: // send body
565: if(!header_only)
1.69 paf 566: SAPI::send_body(pool(), body, content_length);
1.50 paf 567: }
1.104 paf 568:
569: const String& Request::mime_type_of(const char *user_file_name_cstr) {
570: if(mime_types)
571: if(const char *cext=strrchr(user_file_name_cstr, '.')) {
572: String sext(pool(), ++cext);
573: if(mime_types->locate(0, sext))
574: if(const String *result=mime_types->item(1))
575: return *result;
576: else
577: THROW(0, 0,
578: mime_types->origin_string(),
579: "MIME-TYPE table column elements must not be empty");
580: }
581: return *NEW String(pool(), "application/octet-stream");
582: }
E-mail: