http_request.c revision 9b3073cc691d1b5a38a4068d8dfe69f81335cf6d
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* http_request.c: functions to get and process requests
*
* Rob McCool 3/21/93
*
* Thoroughly revamped by rst for Apache. NB this file reads
* best from the bottom up.
*
*/
#include "apr_strings.h"
#include "apr_file_io.h"
#include "apr_fnmatch.h"
#define APR_WANT_STRFUNC
#include "apr_want.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_request.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_log.h"
#include "http_main.h"
#include "util_filter.h"
#include "util_charset.h"
#include "scoreboard.h"
#include "mod_core.h"
#include <stdarg.h>
#endif
/*****************************************************************
*
* Mainline request processing...
*/
/* XXX A cleaner and faster way to do this might be to pass the request_rec
* down the filter chain as a parameter. It would need to change for
* subrequest vs. main request filters; perhaps the subrequest filter could
* make the switch.
*/
static void update_r_in_filters(ap_filter_t *f,
{
while (f) {
if (f->r == from) {
f->r = to;
}
f = f->next;
}
}
{
int recursive_error = 0;
request_rec *r_1st_err = r;
if (type == AP_FILTER_ERROR) {
/*
* Check if we still have the ap_http_header_filter in place. If
* this is the case we should not ignore AP_FILTER_ERROR here because
* it means that we have not sent any response at all and never
* will. This is bad. Sent an internal server error instead.
*/
next = r->output_filters;
}
/*
* If next != NULL then we left the while above because of
* next->frec == ap_http_header_filter
*/
if (next) {
"Custom error page caused AP_FILTER_ERROR");
}
else {
return;
}
}
return;
}
/*
* The following takes care of Apache redirects to custom response URLs
* Note that if we are already dealing with the response to some other
* error condition, we just report on the original error, and give up on
* any attempt to handle the other thing "intelligently"...
*/
if (r_1st_err != r) {
/* The recursive error was caused by an ErrorDocument specifying
* an internal redirect to a bad URI. ap_internal_redirect has
* changed the filter chains to point to the ErrorDocument's
* request_rec. Back out those changes so we can safely use the
* original failing request_rec to send the canned error message.
*
* ap_send_error_response gets rid of existing resource filters
* on the output side, so we can skip those.
*/
}
}
/*
* This test is done here so that none of the auth modules needs to know
* about proxy authentication. They treat it like normal auth, and then
* we tweak the status.
*/
}
/* If we don't want to keep the connection, make sure we mark that the
* connection is not eligible for keepalive. If we want to keep the
* connection, be sure that the request body (if any) has been read.
*/
if (ap_status_drops_connection(r->status)) {
}
/*
* Two types of custom redirects --- plain text, and URLs. Plain text has
* a leading '"', so the URL code, here, is triggered on its absence
*/
if (ap_is_url(custom_response)) {
/*
* The URL isn't local, so lets drop through the rest of this
* apache code, and continue with the usual REDIRECT handler.
* But note that the client will ultimately see the wrong
* status...
*/
r->status = HTTP_MOVED_TEMPORARILY;
}
else if (custom_response[0] == '/') {
const char *error_notes;
* error documents! */
/*
* This redirect needs to be a GET no matter what the original
* method was.
*/
/*
* Provide a special method for modules to communicate
* more informative (than the plain canned) messages to us.
* Propagate them to ErrorDocuments via the ERROR_NOTES variable:
*/
"error-notes")) != NULL) {
}
r->method = "GET";
r->method_number = M_GET;
return;
}
else {
/*
* Dumb user has given us a bad url to redirect to --- fake up
* dying with a recursive server error...
*/
"Invalid error redirection directive: %s",
}
}
}
static void check_pipeline(conn_rec *c)
{
if (c->keepalive != AP_CONN_CLOSE) {
APR_NONBLOCK_READ, 1);
/*
* Error or empty brigade: There is no data present in the input
* filter
*/
c->data_in_input_filters = 0;
}
else {
c->data_in_input_filters = 1;
}
}
}
{
apr_bucket *b;
conn_rec *c = r->connection;
/* Send an EOR bucket through the output filter chain. When
* this bucket is destroyed, the request will be logged and
* its pool will be freed
*/
/* From here onward, it is no longer safe to reference r
* or r->pool, because r->pool may have been destroyed
* already by the EOR bucket's cleanup function.
*/
if (c->cs)
check_pipeline(c);
if (ap_extended_status) {
}
}
void ap_process_async_request(request_rec *r)
{
conn_rec *c = r->connection;
int access_status;
/* Give quick handlers a shot at serving the request on the fast
* path, bypassing all of the other Apache hooks.
*
* This hook was added to enable serving files out of a URI keyed
* content cache ( e.g., Mike Abbott's Quick Shortcut Cache,
* described here: http://oss.sgi.com/projects/apache/mod_qsc.html )
*
* It may have other uses as well, such as routing requests directly to
* content handlers that have the ability to grok HTTP and do their
* own access checking, etc (e.g. servlet engines).
*
* Use this hook with extreme care and only if you know what you are
* doing.
*/
if (ap_extended_status) {
}
if (APLOGrtrace4(r)) {
int i;
"Headers received from client:");
}
}
#if APR_HAS_THREADS
#endif
if (access_status == DECLINED) {
if (access_status == OK) {
}
}
if (access_status == SUSPENDED) {
/* TODO: Should move these steps into a generic function, so modules
* working on a suspended request can also call _ENTRY again.
*/
if (ap_extended_status) {
}
if (c->cs)
#if APR_HAS_THREADS
#endif
return;
}
#if APR_HAS_THREADS
#endif
if (access_status == DONE) {
/* e.g., something not in storage like TRACE */
access_status = OK;
}
if (access_status == OK) {
}
else {
ap_die(access_status, r);
}
}
void ap_process_request(request_rec *r)
{
apr_bucket *b;
conn_rec *c = r->connection;
if (!c->data_in_input_filters) {
b = apr_bucket_flush_create(c->bucket_alloc);
if (APR_STATUS_IS_TIMEUP(rv)) {
/*
* Notice a timeout as an error message. This might be
* valuable for detecting clients with broken network
* connections or possible DoS attacks.
*
* It is still safe to use r / r->pool here as the eor bucket
* could not have been destroyed in the event of a timeout.
*/
"Timeout while writing data for URI %s to the"
" client", r->unparsed_uri);
}
}
if (ap_extended_status) {
}
}
{
int i;
continue;
}
return new;
}
request_rec *r) {
int access_status;
if (ap_is_recursion_limit_exceeded(r)) {
return NULL;
}
/*
* A whole lot of this really ought to be shared with http_protocol.c...
* another missing cleanup. It's particularly inappropriate to be
* setting header_only, etc., here.
*/
/* Must have prev and next pointers set before calling create_request
* hook.
*/
/* Inherit the rest of the protocol info... */
if (location)
}
ap_filter_t *f, *nextf;
/* If this is a subrequest, the filter chain may contain a
* mixture of filters specific to the old request (r), and
* some inherited from r->main. Here, inherit that filter
* chain, and remove all those which are specific to the old
* request; ensuring the subreq filter is left in place. */
f = new->output_filters;
do {
if (f->r == r && f->frec != ap_subreq_core_filter_handle) {
"dropping filter '%s' in internal redirect from %s to %s",
/* To remove the filter, first set f->r to the *new*
* request_rec, so that ->output_filters on 'new' is
* changed (if necessary) when removing the filter. */
f->r = new;
}
f = nextf;
/* Stop at the protocol filters. If a protocol filter has
* been newly installed for this resource, better leave it
* in place, though it's probably a misconfiguration or
* filter bug to get into this state. */
} while (f && f != new->proto_output_filters);
}
else {
/* If this is not a subrequest, clear out all
* resource-specific filters. */
}
/* Begin by presuming any module can make its own path_info assumptions,
* until some module interjects and changes the value.
*/
/*
* XXX: hmm. This is because mod_setenvif and mod_unique_id really need
* to do their thing on internal redirects as well. Perhaps this is a
* misnamed function.
*/
return NULL;
}
return new;
}
/* XXX: Is this function is so bogus and fragile that we deep-6 it? */
{
/* We need to tell POOL_DEBUG that we're guaranteeing that rr->pool
* will exist as long as r->pool. Otherwise we run into troubles because
* some values in this request will be allocated in r->pool, and others in
* rr->pool.
*/
/* copy output headers from subrequest, but leave negotiation headers */
r->headers_out);
r->err_headers_out);
r->subprocess_env);
/* If any filters pointed at the now-defunct rr, we must point them
* at our "new" instance of r. In particular, some of rr's structures
* will now be bogus (say rr->headers_out). If a filter tried to modify
* their f->r structure when it is pointing to rr, the real request_rec
* will not get updated. Fix that here.
*/
if (r->main) {
NULL, r, r->connection);
}
else {
/*
* We need to check if we now have the SUBREQ_CORE filter in our filter
* chain. If this is the case we need to remove it since we are NO
* subrequest. But we need to keep in mind that the SUBREQ_CORE filter
* does not necessarily need to be the first filter in our chain. So we
* need to go through the chain. But we only need to walk up the chain
* until the proto_output_filters as the SUBREQ_CORE filter is below the
* protocol filters.
*/
next = r->output_filters;
&& (next != r->proto_output_filters)) {
}
}
}
}
{
int access_status;
/* ap_die was already called, if an error occured */
if (!new) {
return;
}
if (access_status == DECLINED) {
if (access_status == OK) {
}
}
if (access_status == OK) {
}
else {
}
}
/* This function is designed for things like actions or CGI scripts, when
* using AddHandler, and you want to preserve the content type across
* an internal redirect.
*/
{
int access_status;
/* ap_die was already called, if an error occured */
if (!new) {
return;
}
if (r->handler)
if (access_status == OK) {
return;
}
}
else {
}
}
{
const char *method;
/*
* Get rid of any current settings if requested; not just the
* well-known methods but any extensions as well.
*/
if (reset) {
}
}
}
{
int method;
/*
* Get rid of any current settings if requested; not just the
* well-known methods but any extensions as well.
*/
if (reset) {
}
mask = 0;
}
}