[core] preserve PATH_INFO case on case-insensitive fs (fixes #406)
[lighttpd.git] / src / response.c
blob389b079fd9e6d49ab0efe5566b1bf67b88cd453a
1 #include "first.h"
3 #include "response.h"
4 #include "keyvalue.h"
5 #include "log.h"
6 #include "stat_cache.h"
7 #include "chunk.h"
9 #include "configfile.h"
11 #include "plugin.h"
13 #include <sys/types.h>
14 #include <sys/stat.h>
16 #include <limits.h>
17 #include <errno.h>
18 #include <fcntl.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <time.h>
22 #include <unistd.h>
23 #include <ctype.h>
24 #include <assert.h>
26 #include <stdio.h>
28 #include "sys-socket.h"
29 #include "version.h"
31 int http_response_write_header(server *srv, connection *con) {
32 buffer *b;
33 size_t i;
34 int have_date = 0;
35 int have_server = 0;
37 b = buffer_init();
39 if (con->request.http_version == HTTP_VERSION_1_1) {
40 buffer_copy_string_len(b, CONST_STR_LEN("HTTP/1.1 "));
41 } else {
42 buffer_copy_string_len(b, CONST_STR_LEN("HTTP/1.0 "));
44 buffer_append_int(b, con->http_status);
45 buffer_append_string_len(b, CONST_STR_LEN(" "));
46 buffer_append_string(b, get_http_status_name(con->http_status));
48 /* disable keep-alive if requested */
49 if (con->request_count > con->conf.max_keep_alive_requests || 0 == con->conf.max_keep_alive_idle) {
50 con->keep_alive = 0;
51 } else {
52 con->keep_alive_idle = con->conf.max_keep_alive_idle;
55 if (con->request.http_version != HTTP_VERSION_1_1 || con->keep_alive == 0) {
56 if (con->keep_alive) {
57 response_header_overwrite(srv, con, CONST_STR_LEN("Connection"), CONST_STR_LEN("keep-alive"));
58 } else {
59 response_header_overwrite(srv, con, CONST_STR_LEN("Connection"), CONST_STR_LEN("close"));
63 if (con->response.transfer_encoding & HTTP_TRANSFER_ENCODING_CHUNKED) {
64 response_header_overwrite(srv, con, CONST_STR_LEN("Transfer-Encoding"), CONST_STR_LEN("chunked"));
68 /* add all headers */
69 for (i = 0; i < con->response.headers->used; i++) {
70 data_string *ds;
72 ds = (data_string *)con->response.headers->data[i];
74 if (!buffer_is_empty(ds->value) && !buffer_is_empty(ds->key) &&
75 0 != strncasecmp(ds->key->ptr, CONST_STR_LEN("X-LIGHTTPD-")) &&
76 0 != strncasecmp(ds->key->ptr, CONST_STR_LEN("X-Sendfile"))) {
77 if (0 == strcasecmp(ds->key->ptr, "Date")) have_date = 1;
78 if (0 == strcasecmp(ds->key->ptr, "Server")) have_server = 1;
79 if (0 == strcasecmp(ds->key->ptr, "Content-Encoding") && 304 == con->http_status) continue;
81 buffer_append_string_len(b, CONST_STR_LEN("\r\n"));
82 buffer_append_string_buffer(b, ds->key);
83 buffer_append_string_len(b, CONST_STR_LEN(": "));
84 #if 0
85 /**
86 * the value might contain newlines, encode them with at least one white-space
88 buffer_append_string_encoded(b, CONST_BUF_LEN(ds->value), ENCODING_HTTP_HEADER);
89 #else
90 buffer_append_string_buffer(b, ds->value);
91 #endif
95 if (!have_date) {
96 /* HTTP/1.1 requires a Date: header */
97 buffer_append_string_len(b, CONST_STR_LEN("\r\nDate: "));
99 /* cache the generated timestamp */
100 if (srv->cur_ts != srv->last_generated_date_ts) {
101 buffer_string_prepare_copy(srv->ts_date_str, 255);
103 buffer_append_strftime(srv->ts_date_str, "%a, %d %b %Y %H:%M:%S GMT", gmtime(&(srv->cur_ts)));
105 srv->last_generated_date_ts = srv->cur_ts;
108 buffer_append_string_buffer(b, srv->ts_date_str);
111 if (!have_server) {
112 if (buffer_is_empty(con->conf.server_tag)) {
113 buffer_append_string_len(b, CONST_STR_LEN("\r\nServer: " PACKAGE_DESC));
114 } else if (!buffer_string_is_empty(con->conf.server_tag)) {
115 buffer_append_string_len(b, CONST_STR_LEN("\r\nServer: "));
116 buffer_append_string_encoded(b, CONST_BUF_LEN(con->conf.server_tag), ENCODING_HTTP_HEADER);
120 buffer_append_string_len(b, CONST_STR_LEN("\r\n\r\n"));
122 con->bytes_header = buffer_string_length(b);
124 if (con->conf.log_response_header) {
125 log_error_write(srv, __FILE__, __LINE__, "sSb", "Response-Header:", "\n", b);
128 chunkqueue_prepend_buffer(con->write_queue, b);
129 buffer_free(b);
131 return 0;
134 #ifdef USE_OPENSSL
135 static void https_add_ssl_entries(connection *con) {
136 X509 *xs;
137 X509_NAME *xn;
138 X509_NAME_ENTRY *xe;
139 int i, nentries;
141 if (
142 SSL_get_verify_result(con->ssl) != X509_V_OK
143 || !(xs = SSL_get_peer_certificate(con->ssl))
145 return;
148 xn = X509_get_subject_name(xs);
149 for (i = 0, nentries = X509_NAME_entry_count(xn); i < nentries; ++i) {
150 int xobjnid;
151 const char * xobjsn;
152 data_string *envds;
154 if (!(xe = X509_NAME_get_entry(xn, i))) {
155 continue;
157 xobjnid = OBJ_obj2nid((ASN1_OBJECT*)X509_NAME_ENTRY_get_object(xe));
158 xobjsn = OBJ_nid2sn(xobjnid);
159 if (!xobjsn) {
160 continue;
163 if (NULL == (envds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {
164 envds = data_string_init();
166 buffer_copy_string_len(envds->key, CONST_STR_LEN("SSL_CLIENT_S_DN_"));
167 buffer_append_string(envds->key, xobjsn);
168 buffer_copy_string_len(
169 envds->value,
170 (const char *)X509_NAME_ENTRY_get_data(xe)->data,
171 X509_NAME_ENTRY_get_data(xe)->length
173 /* pick one of the exported values as "REMOTE_USER", for example
174 * ssl.verifyclient.username = "SSL_CLIENT_S_DN_UID" or "SSL_CLIENT_S_DN_emailAddress"
176 if (buffer_is_equal(con->conf.ssl_verifyclient_username, envds->key)) {
177 data_string *ds;
178 if (NULL == (ds = (data_string *)array_get_element(con->environment, "REMOTE_USER"))) {
179 if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {
180 ds = data_string_init();
182 buffer_copy_string(ds->key, "REMOTE_USER");
183 array_insert_unique(con->environment, (data_unset *)ds);
185 buffer_copy_buffer(ds->value, envds->value);
187 array_insert_unique(con->environment, (data_unset *)envds);
189 if (con->conf.ssl_verifyclient_export_cert) {
190 BIO *bio;
191 if (NULL != (bio = BIO_new(BIO_s_mem()))) {
192 data_string *envds;
193 int n;
195 PEM_write_bio_X509(bio, xs);
196 n = BIO_pending(bio);
198 if (NULL == (envds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {
199 envds = data_string_init();
202 buffer_copy_string_len(envds->key, CONST_STR_LEN("SSL_CLIENT_CERT"));
203 buffer_string_prepare_copy(envds->value, n);
204 BIO_read(bio, envds->value->ptr, n);
205 BIO_free(bio);
206 buffer_commit(envds->value, n);
207 array_insert_unique(con->environment, (data_unset *)envds);
210 X509_free(xs);
212 #endif
215 handler_t http_response_prepare(server *srv, connection *con) {
216 handler_t r;
218 /* looks like someone has already done a decision */
219 if (con->mode == DIRECT &&
220 (con->http_status != 0 && con->http_status != 200)) {
221 /* remove a packets in the queue */
222 if (con->file_finished == 0) {
223 chunkqueue_reset(con->write_queue);
226 return HANDLER_FINISHED;
229 /* no decision yet, build conf->filename */
230 if (con->mode == DIRECT && buffer_is_empty(con->physical.path)) {
231 char *qstr;
233 /* we only come here when we have the parse the full request again
235 * a HANDLER_COMEBACK from mod_rewrite and mod_fastcgi might be a
236 * problem here as mod_setenv might get called multiple times
238 * fastcgi-auth might lead to a COMEBACK too
239 * fastcgi again dead server too
241 * mod_compress might add headers twice too
243 * */
245 config_cond_cache_reset(srv, con);
246 config_setup_connection(srv, con); /* Perhaps this could be removed at other places. */
248 if (con->conf.log_condition_handling) {
249 log_error_write(srv, __FILE__, __LINE__, "s", "run condition");
253 * prepare strings
255 * - uri.path_raw
256 * - uri.path (secure)
257 * - uri.query
262 * Name according to RFC 2396
264 * - scheme
265 * - authority
266 * - path
267 * - query
269 * (scheme)://(authority)(path)?(query)#fragment
274 /* initial scheme value. can be overwritten for example by mod_extforward later */
275 if (con->srv_socket->is_ssl) {
276 buffer_copy_string_len(con->uri.scheme, CONST_STR_LEN("https"));
277 } else {
278 buffer_copy_string_len(con->uri.scheme, CONST_STR_LEN("http"));
280 buffer_copy_buffer(con->uri.authority, con->request.http_host);
281 buffer_to_lower(con->uri.authority);
283 /** their might be a fragment which has to be cut away */
284 if (NULL != (qstr = strchr(con->request.uri->ptr, '#'))) {
285 buffer_string_set_length(con->request.uri, qstr - con->request.uri->ptr);
288 /** extract query string from request.uri */
289 if (NULL != (qstr = strchr(con->request.uri->ptr, '?'))) {
290 buffer_copy_string (con->uri.query, qstr + 1);
291 buffer_copy_string_len(con->uri.path_raw, con->request.uri->ptr, qstr - con->request.uri->ptr);
292 } else {
293 buffer_reset (con->uri.query);
294 buffer_copy_buffer(con->uri.path_raw, con->request.uri);
297 /* decode url to path
299 * - decode url-encodings (e.g. %20 -> ' ')
300 * - remove path-modifiers (e.g. /../)
303 if (con->request.http_method == HTTP_METHOD_OPTIONS &&
304 con->uri.path_raw->ptr[0] == '*' && con->uri.path_raw->ptr[1] == '\0') {
305 /* OPTIONS * ... */
306 buffer_copy_buffer(con->uri.path, con->uri.path_raw);
307 } else {
308 buffer_copy_buffer(srv->tmp_buf, con->uri.path_raw);
309 buffer_urldecode_path(srv->tmp_buf);
310 buffer_path_simplify(con->uri.path, srv->tmp_buf);
313 con->conditional_is_valid[COMP_SERVER_SOCKET] = 1; /* SERVERsocket */
314 con->conditional_is_valid[COMP_HTTP_SCHEME] = 1; /* Scheme: */
315 con->conditional_is_valid[COMP_HTTP_HOST] = 1; /* Host: */
316 con->conditional_is_valid[COMP_HTTP_REMOTE_IP] = 1; /* Client-IP */
317 con->conditional_is_valid[COMP_HTTP_REFERER] = 1; /* Referer: */
318 con->conditional_is_valid[COMP_HTTP_USER_AGENT] = /* User-Agent: */
319 con->conditional_is_valid[COMP_HTTP_LANGUAGE] = 1; /* Accept-Language: */
320 con->conditional_is_valid[COMP_HTTP_COOKIE] = 1; /* Cookie: */
321 con->conditional_is_valid[COMP_HTTP_REQUEST_METHOD] = 1; /* REQUEST_METHOD */
322 con->conditional_is_valid[COMP_HTTP_URL] = 1; /* HTTPurl */
323 con->conditional_is_valid[COMP_HTTP_QUERY_STRING] = 1; /* HTTPqs */
324 config_patch_connection(srv, con);
326 #ifdef USE_OPENSSL
327 if (con->srv_socket->is_ssl && con->conf.ssl_verifyclient) {
328 https_add_ssl_entries(con);
330 #endif
332 /* do we have to downgrade to 1.0 ? */
333 if (!con->conf.allow_http11) {
334 con->request.http_version = HTTP_VERSION_1_0;
337 if (con->conf.log_request_handling) {
338 log_error_write(srv, __FILE__, __LINE__, "s", "-- splitting Request-URI");
339 log_error_write(srv, __FILE__, __LINE__, "sb", "Request-URI : ", con->request.uri);
340 log_error_write(srv, __FILE__, __LINE__, "sb", "URI-scheme : ", con->uri.scheme);
341 log_error_write(srv, __FILE__, __LINE__, "sb", "URI-authority : ", con->uri.authority);
342 log_error_write(srv, __FILE__, __LINE__, "sb", "URI-path (raw) : ", con->uri.path_raw);
343 log_error_write(srv, __FILE__, __LINE__, "sb", "URI-path (clean): ", con->uri.path);
344 log_error_write(srv, __FILE__, __LINE__, "sb", "URI-query : ", con->uri.query);
350 * call plugins
352 * - based on the raw URL
356 switch(r = plugins_call_handle_uri_raw(srv, con)) {
357 case HANDLER_GO_ON:
358 break;
359 case HANDLER_FINISHED:
360 case HANDLER_COMEBACK:
361 case HANDLER_WAIT_FOR_EVENT:
362 case HANDLER_ERROR:
363 return r;
364 default:
365 log_error_write(srv, __FILE__, __LINE__, "sd", "handle_uri_raw: unknown return value", r);
366 break;
371 * call plugins
373 * - based on the clean URL
377 switch(r = plugins_call_handle_uri_clean(srv, con)) {
378 case HANDLER_GO_ON:
379 break;
380 case HANDLER_FINISHED:
381 case HANDLER_COMEBACK:
382 case HANDLER_WAIT_FOR_EVENT:
383 case HANDLER_ERROR:
384 return r;
385 default:
386 log_error_write(srv, __FILE__, __LINE__, "");
387 break;
390 if (con->request.http_method == HTTP_METHOD_OPTIONS &&
391 con->uri.path->ptr[0] == '*' && con->uri.path_raw->ptr[1] == '\0') {
392 /* option requests are handled directly without checking of the path */
394 response_header_insert(srv, con, CONST_STR_LEN("Allow"), CONST_STR_LEN("OPTIONS, GET, HEAD, POST"));
396 con->http_status = 200;
397 con->file_finished = 1;
399 return HANDLER_FINISHED;
402 /***
404 * border
406 * logical filename (URI) becomes a physical filename here
415 /* 1. stat()
416 * ... ISREG() -> ok, go on
417 * ... ISDIR() -> index-file -> redirect
419 * 2. pathinfo()
420 * ... ISREG()
422 * 3. -> 404
427 * SEARCH DOCUMENT ROOT
430 /* set a default */
432 buffer_copy_buffer(con->physical.doc_root, con->conf.document_root);
433 buffer_copy_buffer(con->physical.rel_path, con->uri.path);
435 #if defined(__WIN32) || defined(__CYGWIN__)
436 /* strip dots from the end and spaces
438 * windows/dos handle those filenames as the same file
440 * foo == foo. == foo..... == "foo... " == "foo.. ./"
442 * This will affect in some cases PATHINFO
444 * on native windows we could prepend the filename with \\?\ to circumvent
445 * this behaviour. I have no idea how to push this through cygwin
447 * */
449 if (con->physical.rel_path->used > 1) {
450 buffer *b = con->physical.rel_path;
451 size_t len = buffer_string_length(b);
453 /* strip trailing " /" or "./" once */
454 if (len > 1 &&
455 b->ptr[len - 1] == '/' &&
456 (b->ptr[len - 2] == ' ' || b->ptr[len - 2] == '.')) {
457 len -= 2;
459 /* strip all trailing " " and "." */
460 while (len > 0 && ( ' ' == b->ptr[len-1] || '.' == b->ptr[len-1] ) ) --len;
461 buffer_string_set_length(b, len);
463 #endif
465 if (con->conf.log_request_handling) {
466 log_error_write(srv, __FILE__, __LINE__, "s", "-- before doc_root");
467 log_error_write(srv, __FILE__, __LINE__, "sb", "Doc-Root :", con->physical.doc_root);
468 log_error_write(srv, __FILE__, __LINE__, "sb", "Rel-Path :", con->physical.rel_path);
469 log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path);
471 /* the docroot plugin should set the doc_root and might also set the physical.path
472 * for us (all vhost-plugins are supposed to set the doc_root)
473 * */
474 switch(r = plugins_call_handle_docroot(srv, con)) {
475 case HANDLER_GO_ON:
476 break;
477 case HANDLER_FINISHED:
478 case HANDLER_COMEBACK:
479 case HANDLER_WAIT_FOR_EVENT:
480 case HANDLER_ERROR:
481 return r;
482 default:
483 log_error_write(srv, __FILE__, __LINE__, "");
484 break;
487 /* MacOS X and Windows can't distiguish between upper and lower-case
489 * convert to lower-case
491 if (con->conf.force_lowercase_filenames) {
492 buffer_to_lower(con->physical.rel_path);
495 /* the docroot plugins might set the servername, if they don't we take http-host */
496 if (buffer_string_is_empty(con->server_name)) {
497 buffer_copy_buffer(con->server_name, con->uri.authority);
501 * create physical filename
502 * -> physical.path = docroot + rel_path
506 buffer_copy_buffer(con->physical.basedir, con->physical.doc_root);
507 buffer_copy_buffer(con->physical.path, con->physical.doc_root);
508 buffer_append_slash(con->physical.path);
509 if (!buffer_string_is_empty(con->physical.rel_path) &&
510 con->physical.rel_path->ptr[0] == '/') {
511 buffer_append_string_len(con->physical.path, con->physical.rel_path->ptr + 1, buffer_string_length(con->physical.rel_path) - 1);
512 } else {
513 buffer_append_string_buffer(con->physical.path, con->physical.rel_path);
516 if (con->conf.log_request_handling) {
517 log_error_write(srv, __FILE__, __LINE__, "s", "-- after doc_root");
518 log_error_write(srv, __FILE__, __LINE__, "sb", "Doc-Root :", con->physical.doc_root);
519 log_error_write(srv, __FILE__, __LINE__, "sb", "Rel-Path :", con->physical.rel_path);
520 log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path);
523 switch(r = plugins_call_handle_physical(srv, con)) {
524 case HANDLER_GO_ON:
525 break;
526 case HANDLER_FINISHED:
527 case HANDLER_COMEBACK:
528 case HANDLER_WAIT_FOR_EVENT:
529 case HANDLER_ERROR:
530 return r;
531 default:
532 log_error_write(srv, __FILE__, __LINE__, "");
533 break;
536 if (con->conf.log_request_handling) {
537 log_error_write(srv, __FILE__, __LINE__, "s", "-- logical -> physical");
538 log_error_write(srv, __FILE__, __LINE__, "sb", "Doc-Root :", con->physical.doc_root);
539 log_error_write(srv, __FILE__, __LINE__, "sb", "Basedir :", con->physical.basedir);
540 log_error_write(srv, __FILE__, __LINE__, "sb", "Rel-Path :", con->physical.rel_path);
541 log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path);
546 * Noone catched away the file from normal path of execution yet (like mod_access)
548 * Go on and check of the file exists at all
551 if (con->mode == DIRECT) {
552 char *slash = NULL;
553 char *pathinfo = NULL;
554 int found = 0;
555 stat_cache_entry *sce = NULL;
557 if (con->conf.log_request_handling) {
558 log_error_write(srv, __FILE__, __LINE__, "s", "-- handling physical path");
559 log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path);
562 if (HANDLER_ERROR != stat_cache_get_entry(srv, con, con->physical.path, &sce)) {
563 /* file exists */
565 if (con->conf.log_request_handling) {
566 log_error_write(srv, __FILE__, __LINE__, "s", "-- file found");
567 log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path);
569 #ifdef HAVE_LSTAT
570 if ((sce->is_symlink != 0) && !con->conf.follow_symlink) {
571 con->http_status = 403;
573 if (con->conf.log_request_handling) {
574 log_error_write(srv, __FILE__, __LINE__, "s", "-- access denied due symlink restriction");
575 log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path);
578 buffer_reset(con->physical.path);
579 return HANDLER_FINISHED;
581 #endif
582 if (S_ISDIR(sce->st.st_mode)) {
583 if (con->uri.path->ptr[buffer_string_length(con->uri.path) - 1] != '/') {
584 /* redirect to .../ */
586 http_response_redirect_to_directory(srv, con);
588 return HANDLER_FINISHED;
590 #ifdef HAVE_LSTAT
591 } else if (!S_ISREG(sce->st.st_mode) && !sce->is_symlink) {
592 #else
593 } else if (!S_ISREG(sce->st.st_mode)) {
594 #endif
595 /* any special handling of non-reg files ?*/
599 } else {
600 switch (errno) {
601 case EACCES:
602 con->http_status = 403;
604 if (con->conf.log_request_handling) {
605 log_error_write(srv, __FILE__, __LINE__, "s", "-- access denied");
606 log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path);
609 buffer_reset(con->physical.path);
610 return HANDLER_FINISHED;
611 case ENAMETOOLONG:
612 /* file name to be read was too long. return 404 */
613 case ENOENT:
614 con->http_status = 404;
616 if (con->conf.log_request_handling) {
617 log_error_write(srv, __FILE__, __LINE__, "s", "-- file not found");
618 log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path);
621 buffer_reset(con->physical.path);
622 return HANDLER_FINISHED;
623 case ENOTDIR:
624 /* PATH_INFO ! :) */
625 break;
626 default:
627 /* we have no idea what happend. let's tell the user so. */
628 con->http_status = 500;
629 buffer_reset(con->physical.path);
631 log_error_write(srv, __FILE__, __LINE__, "ssbsb",
632 "file not found ... or so: ", strerror(errno),
633 con->uri.path,
634 "->", con->physical.path);
636 return HANDLER_FINISHED;
639 /* not found, perhaps PATHINFO */
641 buffer_copy_buffer(srv->tmp_buf, con->physical.path);
643 do {
644 if (slash) {
645 buffer_copy_string_len(con->physical.path, srv->tmp_buf->ptr, slash - srv->tmp_buf->ptr);
646 } else {
647 buffer_copy_buffer(con->physical.path, srv->tmp_buf);
650 if (HANDLER_ERROR != stat_cache_get_entry(srv, con, con->physical.path, &sce)) {
651 found = S_ISREG(sce->st.st_mode);
652 break;
655 if (pathinfo != NULL) {
656 *pathinfo = '\0';
658 slash = strrchr(srv->tmp_buf->ptr, '/');
660 if (pathinfo != NULL) {
661 /* restore '/' */
662 *pathinfo = '/';
665 if (slash) pathinfo = slash;
666 } while ((found == 0) && (slash != NULL) && ((size_t)(slash - srv->tmp_buf->ptr) > (buffer_string_length(con->physical.basedir) - 1)));
668 if (found == 0) {
669 /* no it really doesn't exists */
670 con->http_status = 404;
672 if (con->conf.log_file_not_found) {
673 log_error_write(srv, __FILE__, __LINE__, "sbsb",
674 "file not found:", con->uri.path,
675 "->", con->physical.path);
678 buffer_reset(con->physical.path);
680 return HANDLER_FINISHED;
683 #ifdef HAVE_LSTAT
684 if ((sce->is_symlink != 0) && !con->conf.follow_symlink) {
685 con->http_status = 403;
687 if (con->conf.log_request_handling) {
688 log_error_write(srv, __FILE__, __LINE__, "s", "-- access denied due symlink restriction");
689 log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path);
692 buffer_reset(con->physical.path);
693 return HANDLER_FINISHED;
695 #endif
697 /* we have a PATHINFO */
698 if (pathinfo) {
699 size_t len = strlen(pathinfo), reqlen;
700 if (con->conf.force_lowercase_filenames
701 && len <= (reqlen = buffer_string_length(con->request.uri))
702 && 0 == strncasecmp(con->request.uri->ptr + reqlen - len, pathinfo, len)) {
703 /* attempt to preserve case-insensitive PATH_INFO
704 * (works in common case where mod_alias, mod_magnet, and other modules
705 * have not modified the PATH_INFO portion of request URI, or did so
706 * with exactly the PATH_INFO desired) */
707 buffer_copy_string_len(con->request.pathinfo, con->request.uri->ptr + reqlen - len, len);
708 } else {
709 buffer_copy_string_len(con->request.pathinfo, pathinfo, len);
713 * shorten uri.path
716 buffer_string_set_length(con->uri.path, buffer_string_length(con->uri.path) - len);
719 if (con->conf.log_request_handling) {
720 log_error_write(srv, __FILE__, __LINE__, "s", "-- after pathinfo check");
721 log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path);
722 log_error_write(srv, __FILE__, __LINE__, "sb", "URI :", con->uri.path);
723 log_error_write(srv, __FILE__, __LINE__, "sb", "Pathinfo :", con->request.pathinfo);
727 if (con->conf.log_request_handling) {
728 log_error_write(srv, __FILE__, __LINE__, "s", "-- handling subrequest");
729 log_error_write(srv, __FILE__, __LINE__, "sb", "Path :", con->physical.path);
732 /* call the handlers */
733 switch(r = plugins_call_handle_subrequest_start(srv, con)) {
734 case HANDLER_GO_ON:
735 /* request was not handled */
736 break;
737 case HANDLER_FINISHED:
738 default:
739 if (con->conf.log_request_handling) {
740 log_error_write(srv, __FILE__, __LINE__, "s", "-- subrequest finished");
743 /* something strange happend */
744 return r;
747 /* if we are still here, no one wanted the file, status 403 is ok I think */
749 if (con->mode == DIRECT && con->http_status == 0) {
750 switch (con->request.http_method) {
751 case HTTP_METHOD_OPTIONS:
752 con->http_status = 200;
753 break;
754 default:
755 con->http_status = 403;
758 return HANDLER_FINISHED;
763 switch(r = plugins_call_handle_subrequest(srv, con)) {
764 case HANDLER_GO_ON:
765 /* request was not handled, looks like we are done */
766 return HANDLER_FINISHED;
767 case HANDLER_FINISHED:
768 /* request is finished */
769 default:
770 /* something strange happend */
771 return r;
774 /* can't happen */
775 return HANDLER_COMEBACK;