static void discard_data(request_rec *r) { #ifdef APACHE2 (void) ap_discard_request_body(r); #else /* * This is taken from ap_discard_request_body(). The reason we can't * just use it in Apache 1.3 is that it does various timeout things we * don't want it to do. Apache 2.0 doesn't do that, so we can safely * use the normal function. */ if (r->read_chunked || r->remaining > 0) { char dumpbuf[HUGE_STRING_LEN]; int i; do { i = ap_get_client_block(r, dumpbuf, HUGE_STRING_LEN); #ifdef DEBUG dump_buffer(stderr, "discarded", dumpbuf, i); #endif } while (i > 0); } #endif }
/* ** Binding to ap_discard_request_body. ** Uses the request_rec defined as an upvalue. ** Returns a status code. */ static int req_discard_request_body (lua_State *L) { request_rec *r = CHECK_REQUEST_OBJECT(1); lua_pushnumber (L, ap_discard_request_body (r)); return 1; }
CAMLprim value netcgi2_apache_request_discard_request_body (value rv) { CAMLparam1 (rv); request_rec *r = Request_rec_val (rv); int i = ap_discard_request_body (r); CAMLreturn (Val_int(i)); /* possible error dealt with on the Caml side */ }
static int read_chars (lua_State *L, request_rec* r, size_t n) { size_t len; char tmpbuf[HUGE_STRING_LEN]; len = HUGE_STRING_LEN; /* try to read that much each time */ if (len > n) len = n; if ( (len = ap_get_client_block(r, tmpbuf, len)) > 0) { lua_pushlstring(L, tmpbuf, len); return 1; } else ap_discard_request_body(r); return 0; }
static int aclr_handler(request_rec *r) { int rc; const char *idhead; char *real_uri; const char *docroot; size_t docroot_len; ap_filter_t *f, *nextf; char iredirect[MAX_STRING_LEN]; aclr_dir_config *cfg = (aclr_dir_config *)ap_get_module_config (r->per_dir_config, &aclr_module); if (cfg->state != ACLR_ENABLED) { return DECLINED; } if (!ap_is_initial_req(r)) { return DECLINED; } idhead = apr_table_get(r->headers_in, xa_int_name); if (idhead == NULL) { return DECLINED; } #ifdef DEBUG const char *server_name = ap_get_server_name(r); #endif docroot = ap_document_root(r); docroot_len = strlen(docroot); /* obtain real URI from filename - for rewrited URIs */ if (strncmp(r->filename, docroot, docroot_len) != 0) { if (cfg->redirect_outside_of_docroot != ACLR_ENABLED) { aclr_debug(2, r->server, "file \"%s\" is outside of " "DocumentRoot \"%s\": %s%s", r->filename, docroot, server_name, r->uri); return DECLINED; } real_uri = r->uri; } else { real_uri = r->filename; real_uri += docroot_len; } snprintf(iredirect, sizeof(iredirect), "%s%s", idhead, real_uri); aclr_debug(3, r->server, "trying to process request: %s%s -> %s", server_name, r->uri, iredirect); aclr_debug(3, r->server, "r->filename: %s", r->filename); aclr_debug(3, r->server, "r->uri: %s", r->uri); aclr_debug(3, r->server, "docroot: %s", docroot); aclr_debug(3, r->server, "real_uri: %s", real_uri); if ((rc = ap_discard_request_body(r)) != OK) { return rc; } apr_table_set(r->headers_out, xa_ver_name, ACLR_VERSION); if ((r->method_number != M_GET) || (r->header_only)) { aclr_debug(2, r->server, "request method is not GET: %s%s", server_name, r->uri); return DECLINED; } if (r->finfo.filetype != APR_REG) { aclr_debug(2, r->server, "request file not found " "or is not regular file: %s%s", server_name, r->uri); return DECLINED; } if (cfg->fsize != UNSET && r->finfo.size < cfg->fsize) { aclr_debug(2, r->server, "file size %lu < minsize %lu: %s%s", r->finfo.size, cfg->fsize, server_name, r->uri); return DECLINED; } f = r->output_filters; do { nextf = f->next; aclr_debug(3, r->server, "output filter: %s", f->frec->name); if (strcmp(f->frec->name, "includes") == 0) { aclr_debug(2, r->server, "request uses INCLUDES filter: %s%s", server_name, r->uri); return DECLINED; } f = nextf; } while (f && f != r->proto_output_filters); apr_table_set(r->headers_out, xa_redir_name, iredirect); r->header_only = 0; ap_update_mtime(r, r->finfo.mtime); aclr_debug(1, r->server, "request %s%s redirected to %s", server_name, r->uri, iredirect); return OK; }
static int file_cache_handler(request_rec *r) { a_file *match; int errstatus; int rc = OK; /* Bail out if r->handler isn't the default value, and doesn't look like a Content-Type * XXX: Even though we made the user explicitly list each path to cache? */ if (ap_strcmp_match(r->handler, "*/*") && !AP_IS_DEFAULT_HANDLER_NAME(r->handler)) { return DECLINED; } /* we don't handle anything but GET */ if (r->method_number != M_GET) return DECLINED; /* did xlat phase find the file? */ match = ap_get_module_config(r->request_config, &file_cache_module); if (match == NULL) { return DECLINED; } /* note that we would handle GET on this resource */ r->allowed |= (AP_METHOD_BIT << M_GET); /* This handler has no use for a request body (yet), but we still * need to read and discard it if the client sent one. */ if ((errstatus = ap_discard_request_body(r)) != OK) return errstatus; ap_update_mtime(r, match->finfo.mtime); /* ap_set_last_modified() always converts the file mtime to a string * which is slow. Accelerate the common case. * ap_set_last_modified(r); */ { apr_time_t mod_time; char *datestr; mod_time = ap_rationalize_mtime(r, r->mtime); if (mod_time == match->finfo.mtime) datestr = match->mtimestr; else { datestr = apr_palloc(r->pool, APR_RFC822_DATE_LEN); apr_rfc822_date(datestr, mod_time); } apr_table_setn(r->headers_out, "Last-Modified", datestr); } /* ap_set_content_length() always converts the same number and never * returns an error. Accelerate it. */ r->clength = match->finfo.size; apr_table_setn(r->headers_out, "Content-Length", match->sizestr); ap_set_etag(r); if ((errstatus = ap_meets_conditions(r)) != OK) { return errstatus; } /* Call appropriate handler */ if (!r->header_only) { if (match->is_mmapped == TRUE) rc = mmap_handler(r, match); else rc = sendfile_handler(r, match); } return rc; }