request.xml revision 5205c3bfe8b0447c455dc95e68a10e7277041e13
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
5f5d1b4cc970b7f06ff8ef6526128e9a27303d88nd<!-- $LastChangedRevision$ -->
031b91a62d25106ae69d4693475c79618dd5e884fielding Licensed to the Apache Software Foundation (ASF) under one or more
031b91a62d25106ae69d4693475c79618dd5e884fielding contributor license agreements. See the NOTICE file distributed with
031b91a62d25106ae69d4693475c79618dd5e884fielding this work for additional information regarding copyright ownership.
031b91a62d25106ae69d4693475c79618dd5e884fielding The ASF licenses this file to You under the Apache License, Version 2.0
031b91a62d25106ae69d4693475c79618dd5e884fielding (the "License"); you may not use this file except in compliance with
031b91a62d25106ae69d4693475c79618dd5e884fielding the License. You may obtain a copy of the License at
816bc7965d58c92c0d02fd42d6ea58090f70c6bdnd Unless required by applicable law or agreed to in writing, software
816bc7965d58c92c0d02fd42d6ea58090f70c6bdnd distributed under the License is distributed on an "AS IS" BASIS,
816bc7965d58c92c0d02fd42d6ea58090f70c6bdnd WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
816bc7965d58c92c0d02fd42d6ea58090f70c6bdnd See the License for the specific language governing permissions and
816bc7965d58c92c0d02fd42d6ea58090f70c6bdnd limitations under the License.
c82fca6d3f5608b946f18d37e8710b1d71e3478dnd<parentdocument href="./">Developer Documentation</parentdocument>
491a6d4de1362a7da74f58311a3be2dbf61db383humbedooh<title>Request Processing in the Apache HTTP Server 2.x</title>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>Warning - this is a first (fast) draft that needs further
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend revision!</p>
491a6d4de1362a7da74f58311a3be2dbf61db383humbedooh <p>Several changes in 2.0 and above affect the internal request
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend processing mechanics. Module authors need to be aware of these
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend changes so they may take advantage of the optimizations and
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend security enhancements.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>The first major change is to the subrequest and redirect
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend mechanisms. There were a number of different code paths in
491a6d4de1362a7da74f58311a3be2dbf61db383humbedooh the Apache HTTP Server 1.3 to attempt to optimize subrequest
491a6d4de1362a7da74f58311a3be2dbf61db383humbedooh or redirect behavior. As patches were introduced to 2.0, these
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend optimizations (and the server behavior) were quickly broken due
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend to this duplication of code. All duplicate code has been folded
dc06c0ac17fcd3d721bb865d7fc5d2cefe67c57ftrawick back into <code>ap_process_request_internal()</code> to prevent
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend the code from falling out of sync again.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>This means that much of the existing code was 'unoptimized'.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend It is the Apache HTTP Project's first goal to create a robust
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend and correct implementation of the HTTP server RFC. Additional
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend goals include security, scalability and optimization. New
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend methods were sought to optimize the server (beyond the
491a6d4de1362a7da74f58311a3be2dbf61db383humbedooh performance of 1.3) without introducing fragile or
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend insecure code.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend<section id="processing"><title>The Request Processing Cycle</title>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>All requests pass through <code>ap_process_request_internal()</code>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend in <code>request.c</code>, including subrequests and redirects. If a module
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend doesn't pass generated requests through this code, the author is cautioned
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend that the module may be broken by future changes to request
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend processing.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>To streamline requests, the module author can take advantage
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend of the hooks offered to drop out of the request cycle early, or
491a6d4de1362a7da74f58311a3be2dbf61db383humbedooh to bypass core hooks which are irrelevant (and costly in
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend terms of CPU.)</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend<section id="parsing"><title>The Request Parsing Phase</title>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>The request's <code>parsed_uri</code> path is unescaped, once and only
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend once, at the beginning of internal request processing.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>This step is bypassed if the proxyreq flag is set, or the
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <code>parsed_uri.path</code> element is unset. The module has no further
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend control of this one-time unescape operation, either failing to
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend unescape or multiply unescaping the URL leads to security
d8925e7b1eb8644294705d7132173f6fcfe0350ahumbedooh repercussions.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend </section>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <section id="strip"><title>Strips Parent and This Elements from the
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend URI</title>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>All <code>/../</code> and <code>/./</code> elements are
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend removed by <code>ap_getparents()</code>. This helps to ensure
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend the path is (nearly) absolute before the request processing
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend continues.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend </section>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <section id="inital-location-walk"><title>Initial URI Location Walk</title>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>Every request is subject to an
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <directive type="section" module="core">Location</directive> sections
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend are consistently enforced for all requests. If the request is an internal
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend redirect or a sub-request, it may borrow some or all of the processing
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend from the previous or parent request's ap_location_walk, so this step
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend is generally very efficient after processing the main request.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend </section>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <section id="translate_name"><title>translate_name</title>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>Modules can determine the file name, or alter the given URI
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend in this step. For example, <module>mod_vhost_alias</module> will
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend translate the URI's path into the configured virtual host,
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <module>mod_alias</module> will translate the path to an alias path,
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend and if the request falls back on the core, the <directive module="core"
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend >DocumentRoot</directive> is prepended to the request resource.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>If all modules <code>DECLINE</code> this phase, an error 500 is
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend returned to the browser, and a "couldn't translate name" error is logged
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend automatically.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend </section>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <section id="map_to_storage"><title>Hook: map_to_storage</title>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>After the file or correct URI was determined, the
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend appropriate per-dir configurations are merged together. For
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend example, <module>mod_proxy</module> compares and merges the appropriate
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <directive module="mod_proxy" type="section">Proxy</directive> sections.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend If the URI is nothing more than a local (non-proxy) <code>TRACE</code>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend request, the core handles the request and returns <code>DONE</code>.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend If no module answers this hook with <code>OK</code> or <code>DONE</code>,
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend the core will run the request filename against the <directive
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend module="core" type="section">Directory</directive> and <directive
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend module="core" type="section">Files</directive> sections. If the request
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend 'filename' isn't an absolute, legal filename, a note is set for
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend later termination.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend </section>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <section id="location-walk"><title>URI Location Walk</title>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>Every request is hardened by a second
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <code>ap_location_walk()</code> call. This reassures that a
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend translated request is still subjected to the configured
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <directive module="core" type="section">Location</directive> sections.
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend The request again borrows some or all of the processing from its previous
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <code>location_walk</code> above, so this step is almost always very
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend efficient unless the translated URI mapped to a substantially different
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend path or Virtual Host.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend </section>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <section id="header_parser"><title>Hook: header_parser</title>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>The main request then parses the client's headers. This
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend prepares the remaining request processing steps to better serve
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend the client's request.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend </section>
5205c3bfe8b0447c455dc95e68a10e7277041e13humbedoohif ((access_status = ap_run_access_checker(r)) != 0) {
5205c3bfe8b0447c455dc95e68a10e7277041e13humbedooh return decl_die(access_status, "check access", r);
5205c3bfe8b0447c455dc95e68a10e7277041e13humbedoohif ((access_status = ap_run_check_user_id(r)) != 0) {
5205c3bfe8b0447c455dc95e68a10e7277041e13humbedooh return decl_die(access_status, "check user", r);
5205c3bfe8b0447c455dc95e68a10e7277041e13humbedoohif ((access_status = ap_run_auth_checker(r)) != 0) {
5205c3bfe8b0447c455dc95e68a10e7277041e13humbedooh return decl_die(access_status, "check authorization", r);
1050464f9f91f75e7a1c5c3daf3fb7b8aa74592ahumbedooh </highlight>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend<section id="preparation"><title>The Preparation Phase</title>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <section id="type_checker"><title>Hook: type_checker</title>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>The modules have an opportunity to test the URI or filename
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend against the target resource, and set mime information for the
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <module>mod_mime_magic</module> use this phase to compare the file
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend name or contents against the administrator's configuration and set the
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend content type, language, character set and request handler. Some modules
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend may set up their filters or other request handling parameters at this
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>If all modules <code>DECLINE</code> this phase, an error 500 is
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend returned to the browser, and a "couldn't find types" error is logged
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend automatically.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend </section>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>Many modules are 'trounced' by some phase above. The fixups
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend phase is used by modules to 'reassert' their ownership or force
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend the request's fields to their appropriate values. It isn't
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend always the cleanest mechanism, but occasionally it's the only
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend option.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend </section>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>This phase is <strong>not</strong> part of the processing in
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend modules prepare one or more subrequests prior to creating any
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend content at all. After the core, or a module calls
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <code>ap_invoke_handler()</code> to generate the request.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <section id="insert_filter"><title>Hook: insert_filter</title>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>Modules that transform the content in some way can insert
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend their values and override existing filters, such that if the
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend user configured a more advanced filter out-of-order, then the
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend module can move its order as need be. There is no result code,
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend so actions in this hook better be trusted to always succeed.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend </section>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend <p>The module finally has a chance to serve the request in its
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend handler hook. Note that not every prepared request is sent to
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend the handler hook. Many modules, such as <module>mod_autoindex</module>,
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend will create subrequests for a given URI, and then never serve the
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend subrequest, but simply lists it for the user. Remember not to
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend put required teardown from the hooks above into this module,
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend but register pool cleanups against the request pool to free
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend resources as required.</p>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend </section>
38dd0bd0209a7e29ea44e66bfc3bec8edc03e9aend</manualpage>