http_request.c revision a0944d0cea0301ca402cfc896485d03da0d6209c
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny/* Licensed to the Apache Software Foundation (ASF) under one or more
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * contributor license agreements. See the NOTICE file distributed with
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * this work for additional information regarding copyright ownership.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * The ASF licenses this file to You under the Apache License, Version 2.0
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * (the "License"); you may not use this file except in compliance with
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * the License. You may obtain a copy of the License at
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * http://www.apache.org/licenses/LICENSE-2.0
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * Unless required by applicable law or agreed to in writing, software
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * distributed under the License is distributed on an "AS IS" BASIS,
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * See the License for the specific language governing permissions and
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * limitations under the License.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny */
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny/*
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * http_request.c: functions to get and process requests
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * Rob McCool 3/21/93
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * Thoroughly revamped by rst for Apache. NB this file reads
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * best from the bottom up.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek#include "apr_strings.h"
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek#include "apr_file_io.h"
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#include "apr_fnmatch.h"
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#define APR_WANT_STRFUNC
46c5deedec570bb5f99702a933ba99d76f9f09cbJakub Hrozek#include "apr_want.h"
46c5deedec570bb5f99702a933ba99d76f9f09cbJakub Hrozek
46c5deedec570bb5f99702a933ba99d76f9f09cbJakub Hrozek#include "ap_config.h"
46c5deedec570bb5f99702a933ba99d76f9f09cbJakub Hrozek#include "httpd.h"
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#include "http_config.h"
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#include "http_request.h"
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek#include "http_core.h"
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek#include "http_protocol.h"
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek#include "http_log.h"
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek#include "http_main.h"
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek#include "util_filter.h"
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#include "util_charset.h"
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#include "scoreboard.h"
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek#include "mod_core.h"
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek#if APR_HAVE_STDARG_H
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#include <stdarg.h>
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek#endif
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub HrozekAPLOG_USE_MODULE(http);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny/*****************************************************************
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek *
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * Mainline request processing...
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny/* XXX A cleaner and faster way to do this might be to pass the request_rec
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * down the filter chain as a parameter. It would need to change for
46c5deedec570bb5f99702a933ba99d76f9f09cbJakub Hrozek * subrequest vs. main request filters; perhaps the subrequest filter could
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * make the switch.
bdbf4f169e4d5d00b0616df19f7a55debb407f78Pavel Březina */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekstatic void update_r_in_filters(ap_filter_t *f,
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny request_rec *from,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek request_rec *to)
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek{
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny while (f) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (f->r == from) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek f->r = to;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny f = f->next;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek}
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan ZelenyAP_DECLARE(void) ap_die(int type, request_rec *r)
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny{
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek int error_index = ap_index_of_response(type);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny char *custom_response = ap_response_code_string(r, error_index);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek int recursive_error = 0;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek request_rec *r_1st_err = r;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (type == AP_FILTER_ERROR) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny ap_filter_t *next;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny /*
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * Check if we still have the ap_http_header_filter in place. If
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * this is the case we should not ignore AP_FILTER_ERROR here because
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * it means that we have not sent any response at all and never
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * will. This is bad. Sent an internal server error instead.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny */
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny next = r->output_filters;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny while (next && (next->frec != ap_http_header_filter_handle)) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny next = next->next;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny /*
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * If next != NULL then we left the while above because of
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * next->frec == ap_http_header_filter
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov */
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (next) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny "Custom error page caused AP_FILTER_ERROR");
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny type = HTTP_INTERNAL_SERVER_ERROR;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov else {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny return;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (type == DONE) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny ap_finalize_request_protocol(r);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny return;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny /*
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov * The following takes care of Apache redirects to custom response URLs
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * Note that if we are already dealing with the response to some other
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * error condition, we just report on the original error, and give up on
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * any attempt to handle the other thing "intelligently"...
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny */
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (r->status != HTTP_OK) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny recursive_error = type;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek while (r_1st_err->prev && (r_1st_err->prev->status != HTTP_OK))
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek r_1st_err = r_1st_err->prev; /* Get back to original error */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (r_1st_err != r) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek /* The recursive error was caused by an ErrorDocument specifying
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * an internal redirect to a bad URI. ap_internal_redirect has
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * changed the filter chains to point to the ErrorDocument's
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * request_rec. Back out those changes so we can safely use the
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * original failing request_rec to send the canned error message.
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek *
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * ap_send_error_response gets rid of existing resource filters
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * on the output side, so we can skip those.
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek update_r_in_filters(r_1st_err->proto_output_filters, r, r_1st_err);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek update_r_in_filters(r_1st_err->input_filters, r, r_1st_err);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek custom_response = NULL; /* Do NOT retry the custom thing! */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek r->status = type;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek /*
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * This test is done here so that none of the auth modules needs to know
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * about proxy authentication. They treat it like normal auth, and then
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * we tweak the status.
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (HTTP_UNAUTHORIZED == r->status && PROXYREQ_PROXY == r->proxyreq) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek r->status = HTTP_PROXY_AUTHENTICATION_REQUIRED;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek /* If we don't want to keep the connection, make sure we mark that the
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * connection is not eligible for keepalive. If we want to keep the
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * connection, be sure that the request body (if any) has been read.
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (ap_status_drops_connection(r->status)) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek r->connection->keepalive = AP_CONN_CLOSE;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek /*
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * Two types of custom redirects --- plain text, and URLs. Plain text has
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov * a leading '"', so the URL code, here, is triggered on its absence
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (custom_response && custom_response[0] != '"') {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (ap_is_url(custom_response)) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek /*
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * The URL isn't local, so lets drop through the rest of this
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * apache code, and continue with the usual REDIRECT handler.
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov * But note that the client will ultimately see the wrong
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * status...
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov r->status = HTTP_MOVED_TEMPORARILY;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov apr_table_setn(r->headers_out, "Location", custom_response);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek else if (custom_response[0] == '/') {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek const char *error_notes;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek r->no_local_copy = 1; /* Do NOT send HTTP_NOT_MODIFIED for
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * error documents! */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek /*
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * This redirect needs to be a GET no matter what the original
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * method was.
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek apr_table_setn(r->subprocess_env, "REQUEST_METHOD", r->method);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek /*
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * Provide a special method for modules to communicate
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * more informative (than the plain canned) messages to us.
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * Propagate them to ErrorDocuments via the ERROR_NOTES variable:
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if ((error_notes = apr_table_get(r->notes,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek "error-notes")) != NULL) {
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce apr_table_setn(r->subprocess_env, "ERROR_NOTES", error_notes);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek r->method = apr_pstrdup(r->pool, "GET");
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek r->method_number = M_GET;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek ap_internal_redirect(custom_response, r);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek return;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek else {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek /*
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * Dumb user has given us a bad url to redirect to --- fake up
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * dying with a recursive server error...
b6d5f2a91fbce15c7ef4d382fa6b52407adb26ddPavel Březina */
b6d5f2a91fbce15c7ef4d382fa6b52407adb26ddPavel Březina recursive_error = HTTP_INTERNAL_SERVER_ERROR;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek "Invalid error redirection directive: %s",
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek custom_response);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek ap_send_error_response(r_1st_err, recursive_error);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek}
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bosestatic void check_pipeline(conn_rec *c)
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek{
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (c->keepalive != AP_CONN_CLOSE) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek apr_status_t rv;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek apr_bucket_brigade *bb = apr_brigade_create(c->pool, c->bucket_alloc);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek rv = ap_get_brigade(c->input_filters, bb, AP_MODE_SPECULATIVE,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek APR_NONBLOCK_READ, 1);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (rv != APR_SUCCESS || APR_BRIGADE_EMPTY(bb)) {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek /*
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * Error or empty brigade: There is no data present in the input
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * filter
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek c->data_in_input_filters = 0;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek else {
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek c->data_in_input_filters = 1;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny apr_brigade_destroy(bb);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny}
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub HrozekAP_DECLARE(void) ap_process_request_after_handler(request_rec *r)
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny{
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny apr_bucket_brigade *bb;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny apr_bucket *b;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny conn_rec *c = r->connection;
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny /* Send an EOR bucket through the output filter chain. When
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov * this bucket is destroyed, the request will be logged and
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov * its pool will be freed
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny */
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny bb = apr_brigade_create(r->connection->pool, r->connection->bucket_alloc);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny b = ap_bucket_eor_create(r->connection->bucket_alloc, r);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek APR_BRIGADE_INSERT_HEAD(bb, b);
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek ap_pass_brigade(r->connection->output_filters, bb);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek /* From here onward, it is no longer safe to reference r
0232747f04b650796db56fd7b487aee8a96fab03Simo Sorce * or r->pool, because r->pool may have been destroyed
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * already by the EOR bucket's cleanup function.
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek */
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek if (c->cs)
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose c->cs->state = CONN_STATE_WRITE_COMPLETION;
bdbf4f169e4d5d00b0616df19f7a55debb407f78Pavel Březina check_pipeline(c);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek AP_PROCESS_REQUEST_RETURN((uintptr_t)r, r->uri, r->status);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (ap_extended_status) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny ap_time_process_request(c->sbh, STOP_PREQUEST);
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek }
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek}
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozekvoid ap_process_async_request(request_rec *r)
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek{
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek conn_rec *c = r->connection;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny int access_status;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny /* Give quick handlers a shot at serving the request on the fast
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * path, bypassing all of the other Apache hooks.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * This hook was added to enable serving files out of a URI keyed
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * content cache ( e.g., Mike Abbott's Quick Shortcut Cache,
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek * described here: http://oss.sgi.com/projects/apache/mod_qsc.html )
8ba8222afca3026fd67af08e224b1d9e848aceaaJakub Hrozek *
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * It may have other uses as well, such as routing requests directly to
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * content handlers that have the ability to grok HTTP and do their
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * own access checking, etc (e.g. servlet engines).
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce *
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce * Use this hook with extreme care and only if you know what you are
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce * doing.
65393a294e635822c1d7a15fe5853dc457ad8a2aSimo Sorce */
aac3ca699a09090072ae4d68bdda8dec990ae393Sumit Bose AP_PROCESS_REQUEST_ENTRY((uintptr_t)r, r->uri);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov if (ap_extended_status) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ap_time_process_request(r->connection->sbh, START_PREQUEST);
aac3ca699a09090072ae4d68bdda8dec990ae393Sumit Bose }
aac3ca699a09090072ae4d68bdda8dec990ae393Sumit Bose
aac3ca699a09090072ae4d68bdda8dec990ae393Sumit Bose if (APLOGrtrace4(r)) {
aac3ca699a09090072ae4d68bdda8dec990ae393Sumit Bose int i;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce const apr_array_header_t *t_h = apr_table_elts(r->headers_in);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce const apr_table_entry_t *t_elt = (apr_table_entry_t *)t_h->elts;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ap_log_rerror(APLOG_MARK, APLOG_TRACE4, 0, r,
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce "Headers received from client:");
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce for (i = 0; i < t_h->nelts; i++, t_elt++) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ap_log_rerror(APLOG_MARK, APLOG_TRACE4, 0, r, " %s: %s",
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ap_escape_logitem(r->pool, t_elt->key),
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ap_escape_logitem(r->pool, t_elt->val));
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#if APR_HAS_THREADS
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny apr_thread_mutex_create(&r->invoke_mtx, APR_THREAD_MUTEX_DEFAULT, r->pool);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny apr_thread_mutex_lock(r->invoke_mtx);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#endif
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny access_status = ap_run_quick_handler(r, 0); /* Not a look-up request */
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (access_status == DECLINED) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny access_status = ap_process_request_internal(r);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (access_status == OK) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny access_status = ap_invoke_handler(r);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (access_status == SUSPENDED) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny /* TODO: Should move these steps into a generic function, so modules
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * working on a suspended request can also call _ENTRY again.
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny */
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny AP_PROCESS_REQUEST_RETURN((uintptr_t)r, r->uri, access_status);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (ap_extended_status) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny ap_time_process_request(c->sbh, STOP_PREQUEST);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (c->cs)
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny c->cs->state = CONN_STATE_SUSPENDED;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny#if APR_HAS_THREADS
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose apr_thread_mutex_unlock(r->invoke_mtx);
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose#endif
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose return;
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose }
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose#if APR_HAS_THREADS
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose apr_thread_mutex_unlock(r->invoke_mtx);
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose#endif
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov if (access_status == DONE) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov /* e.g., something not in storage like TRACE */
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose access_status = OK;
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose }
99bac83188601c2b07e0b141aac7dc7d882b464aSumit Bose
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (access_status == OK) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny ap_finalize_request_protocol(r);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny else {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny r->status = HTTP_OK;
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny ap_die(access_status, r);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce }
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny ap_process_request_after_handler(r);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny}
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zelenyvoid ap_process_request(request_rec *r)
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny{
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce apr_bucket_brigade *bb;
4f118e3e6a25762f40a43e6dbefb09f44adbef32Simo Sorce apr_bucket *b;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce conn_rec *c = r->connection;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce apr_status_t rv;
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce ap_process_async_request(r);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce if (!c->data_in_input_filters) {
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce bb = apr_brigade_create(c->pool, c->bucket_alloc);
bba1a5fd62cffcae076d1351df5a83fbc4a6ec17Simo Sorce b = apr_bucket_flush_create(c->bucket_alloc);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny APR_BRIGADE_INSERT_HEAD(bb, b);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny rv = ap_pass_brigade(c->output_filters, bb);
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny if (APR_STATUS_IS_TIMEUP(rv)) {
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny /*
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * Notice a timeout as an error message. This might be
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * valuable for detecting clients with broken network
c0f9698cd951b7223f251ff2511c4b22a6e4ba60Jan Zeleny * connections or possible DoS attacks.
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose *
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose * It is still safe to use r / r->pool here as the eor bucket
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose * could not have been destroyed in the event of a timeout.
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose */
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose "Timeout while writing data for URI %s to the"
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose " client", r->unparsed_uri);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov }
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose if (ap_extended_status) {
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose ap_time_process_request(c->sbh, STOP_PREQUEST);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose }
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose}
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bosestatic apr_table_t *rename_original_env(apr_pool_t *p, apr_table_t *t)
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose{
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose const apr_array_header_t *env_arr = apr_table_elts(t);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose const apr_table_entry_t *elts = (const apr_table_entry_t *) env_arr->elts;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose apr_table_t *new = apr_table_make(p, env_arr->nalloc);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose int i;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose for (i = 0; i < env_arr->nelts; ++i) {
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose if (!elts[i].key)
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose continue;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose apr_table_setn(new, apr_pstrcat(p, "REDIRECT_", elts[i].key, NULL),
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov elts[i].val);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose }
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose return new;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose}
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bosestatic request_rec *internal_internal_redirect(const char *new_uri,
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose request_rec *r) {
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose int access_status;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose request_rec *new;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose if (ap_is_recursion_limit_exceeded(r)) {
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose ap_die(HTTP_INTERNAL_SERVER_ERROR, r);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose return NULL;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose }
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov new = (request_rec *) apr_pcalloc(r->pool, sizeof(request_rec));
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose new->connection = r->connection;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose new->server = r->server;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose new->pool = r->pool;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose /*
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose * 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.
*/
new->method = r->method;
new->method_number = r->method_number;
new->allowed_methods = ap_make_method_list(new->pool, 2);
ap_parse_uri(new, new_uri);
new->parsed_uri.port_str = r->parsed_uri.port_str;
new->parsed_uri.port = r->parsed_uri.port;
new->request_config = ap_create_request_config(r->pool);
new->per_dir_config = r->server->lookup_defaults;
new->prev = r;
r->next = new;
/* Must have prev and next pointers set before calling create_request
* hook.
*/
ap_run_create_request(new);
/* Inherit the rest of the protocol info... */
new->the_request = r->the_request;
new->allowed = r->allowed;
new->status = r->status;
new->assbackwards = r->assbackwards;
new->header_only = r->header_only;
new->protocol = r->protocol;
new->proto_num = r->proto_num;
new->hostname = r->hostname;
new->request_time = r->request_time;
new->main = r->main;
new->headers_in = r->headers_in;
new->headers_out = apr_table_make(r->pool, 12);
if (ap_is_HTTP_REDIRECT(new->status)) {
const char *location = apr_table_get(r->headers_out, "Location");
if (location)
apr_table_setn(new->headers_out, "Location", location);
}
new->err_headers_out = r->err_headers_out;
new->subprocess_env = rename_original_env(r->pool, r->subprocess_env);
new->notes = apr_table_make(r->pool, 5);
new->htaccess = r->htaccess;
new->no_cache = r->no_cache;
new->expecting_100 = r->expecting_100;
new->no_local_copy = r->no_local_copy;
new->read_length = r->read_length; /* We can only read it once */
new->vlist_validator = r->vlist_validator;
new->proto_output_filters = r->proto_output_filters;
new->proto_input_filters = r->proto_input_filters;
new->input_filters = new->proto_input_filters;
if (new->main) {
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. */
new->output_filters = r->output_filters;
f = new->output_filters;
do {
nextf = f->next;
if (f->r == r && f->frec != ap_subreq_core_filter_handle) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
"dropping filter '%s' in internal redirect from %s to %s",
f->frec->name, r->unparsed_uri, new_uri);
/* 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;
ap_remove_output_filter(f);
}
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. */
new->output_filters = new->proto_output_filters;
}
update_r_in_filters(new->input_filters, r, new);
update_r_in_filters(new->output_filters, r, new);
apr_table_setn(new->subprocess_env, "REDIRECT_STATUS",
apr_itoa(r->pool, r->status));
/* Begin by presuming any module can make its own path_info assumptions,
* until some module interjects and changes the value.
*/
new->used_path_info = AP_REQ_DEFAULT_PATH_INFO;
/*
* 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.
*/
if ((access_status = ap_run_post_read_request(new))) {
ap_die(access_status, new);
return NULL;
}
return new;
}
/* XXX: Is this function is so bogus and fragile that we deep-6 it? */
AP_DECLARE(void) ap_internal_fast_redirect(request_rec *rr, request_rec *r)
{
/* 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.
*/
apr_pool_join(r->pool, rr->pool);
r->proxyreq = rr->proxyreq;
r->no_cache = (r->no_cache && rr->no_cache);
r->no_local_copy = (r->no_local_copy && rr->no_local_copy);
r->mtime = rr->mtime;
r->uri = rr->uri;
r->filename = rr->filename;
r->canonical_filename = rr->canonical_filename;
r->path_info = rr->path_info;
r->args = rr->args;
r->finfo = rr->finfo;
r->handler = rr->handler;
ap_set_content_type(r, rr->content_type);
r->content_encoding = rr->content_encoding;
r->content_languages = rr->content_languages;
r->per_dir_config = rr->per_dir_config;
/* copy output headers from subrequest, but leave negotiation headers */
r->notes = apr_table_overlay(r->pool, rr->notes, r->notes);
r->headers_out = apr_table_overlay(r->pool, rr->headers_out,
r->headers_out);
r->err_headers_out = apr_table_overlay(r->pool, rr->err_headers_out,
r->err_headers_out);
r->subprocess_env = apr_table_overlay(r->pool, rr->subprocess_env,
r->subprocess_env);
r->output_filters = rr->output_filters;
r->input_filters = rr->input_filters;
/* 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.
*/
update_r_in_filters(r->input_filters, rr, r);
update_r_in_filters(r->output_filters, rr, r);
if (r->main) {
ap_add_output_filter_handle(ap_subreq_core_filter_handle,
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.
*/
ap_filter_t *next;
next = r->output_filters;
while (next && (next->frec != ap_subreq_core_filter_handle)
&& (next != r->proto_output_filters)) {
next = next->next;
}
if (next && (next->frec == ap_subreq_core_filter_handle)) {
ap_remove_output_filter(next);
}
}
}
AP_DECLARE(void) ap_internal_redirect(const char *new_uri, request_rec *r)
{
request_rec *new = internal_internal_redirect(new_uri, r);
int access_status;
AP_INTERNAL_REDIRECT(r->uri, new_uri);
/* ap_die was already called, if an error occured */
if (!new) {
return;
}
access_status = ap_run_quick_handler(new, 0); /* Not a look-up request */
if (access_status == DECLINED) {
access_status = ap_process_request_internal(new);
if (access_status == OK) {
access_status = ap_invoke_handler(new);
}
}
if (access_status == OK) {
ap_finalize_request_protocol(new);
}
else {
ap_die(access_status, new);
}
}
/* 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.
*/
AP_DECLARE(void) ap_internal_redirect_handler(const char *new_uri, request_rec *r)
{
int access_status;
request_rec *new = internal_internal_redirect(new_uri, r);
/* ap_die was already called, if an error occured */
if (!new) {
return;
}
if (r->handler)
ap_set_content_type(new, r->content_type);
access_status = ap_process_request_internal(new);
if (access_status == OK) {
if ((access_status = ap_invoke_handler(new)) != 0) {
ap_die(access_status, new);
return;
}
ap_finalize_request_protocol(new);
}
else {
ap_die(access_status, new);
}
}
AP_DECLARE(void) ap_allow_methods(request_rec *r, int reset, ...)
{
const char *method;
va_list methods;
/*
* Get rid of any current settings if requested; not just the
* well-known methods but any extensions as well.
*/
if (reset) {
ap_clear_method_list(r->allowed_methods);
}
va_start(methods, reset);
while ((method = va_arg(methods, const char *)) != NULL) {
ap_method_list_add(r->allowed_methods, method);
}
va_end(methods);
}
AP_DECLARE(void) ap_allow_standard_methods(request_rec *r, int reset, ...)
{
int method;
va_list methods;
apr_int64_t mask;
/*
* Get rid of any current settings if requested; not just the
* well-known methods but any extensions as well.
*/
if (reset) {
ap_clear_method_list(r->allowed_methods);
}
mask = 0;
va_start(methods, reset);
while ((method = va_arg(methods, int)) != -1) {
mask |= (AP_METHOD_BIT << method);
}
va_end(methods);
r->allowed_methods->method_mask |= mask;
}