http_protocol.h revision 2864362ca8266097928e84f101010bdf814ffa08
e609c337f729875bc20e01096c7e610f45356f54nilgun/* ====================================================================
e609c337f729875bc20e01096c7e610f45356f54nilgun * The Apache Software License, Version 1.1
e609c337f729875bc20e01096c7e610f45356f54nilgun * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
e609c337f729875bc20e01096c7e610f45356f54nilgun * reserved.
e609c337f729875bc20e01096c7e610f45356f54nilgun * Redistribution and use in source and binary forms, with or without
e609c337f729875bc20e01096c7e610f45356f54nilgun * modification, are permitted provided that the following conditions
e609c337f729875bc20e01096c7e610f45356f54nilgun * 1. Redistributions of source code must retain the above copyright
e609c337f729875bc20e01096c7e610f45356f54nilgun * notice, this list of conditions and the following disclaimer.
e609c337f729875bc20e01096c7e610f45356f54nilgun * 2. Redistributions in binary form must reproduce the above copyright
e609c337f729875bc20e01096c7e610f45356f54nilgun * notice, this list of conditions and the following disclaimer in
e609c337f729875bc20e01096c7e610f45356f54nilgun * the documentation and/or other materials provided with the
e609c337f729875bc20e01096c7e610f45356f54nilgun * distribution.
e609c337f729875bc20e01096c7e610f45356f54nilgun * 3. The end-user documentation included with the redistribution,
e609c337f729875bc20e01096c7e610f45356f54nilgun * if any, must include the following acknowledgment:
e609c337f729875bc20e01096c7e610f45356f54nilgun * "This product includes software developed by the
e609c337f729875bc20e01096c7e610f45356f54nilgun * Apache Software Foundation (http://www.apache.org/)."
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung * Alternately, this acknowledgment may appear in the software itself,
e609c337f729875bc20e01096c7e610f45356f54nilgun * if and wherever such third-party acknowledgments normally appear.
e609c337f729875bc20e01096c7e610f45356f54nilgun * 4. The names "Apache" and "Apache Software Foundation" must
e609c337f729875bc20e01096c7e610f45356f54nilgun * not be used to endorse or promote products derived from this
e609c337f729875bc20e01096c7e610f45356f54nilgun * software without prior written permission. For written
e609c337f729875bc20e01096c7e610f45356f54nilgun * permission, please contact apache@apache.org.
e609c337f729875bc20e01096c7e610f45356f54nilgun * 5. Products derived from this software may not be called "Apache",
e609c337f729875bc20e01096c7e610f45356f54nilgun * nor may "Apache" appear in their name, without prior written
e609c337f729875bc20e01096c7e610f45356f54nilgun * permission of the Apache Software Foundation.
e609c337f729875bc20e01096c7e610f45356f54nilgun * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
e609c337f729875bc20e01096c7e610f45356f54nilgun * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
e609c337f729875bc20e01096c7e610f45356f54nilgun * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
e609c337f729875bc20e01096c7e610f45356f54nilgun * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
e609c337f729875bc20e01096c7e610f45356f54nilgun * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
e609c337f729875bc20e01096c7e610f45356f54nilgun * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
e609c337f729875bc20e01096c7e610f45356f54nilgun * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
e609c337f729875bc20e01096c7e610f45356f54nilgun * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
e609c337f729875bc20e01096c7e610f45356f54nilgun * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
e609c337f729875bc20e01096c7e610f45356f54nilgun * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
e609c337f729875bc20e01096c7e610f45356f54nilgun * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
e609c337f729875bc20e01096c7e610f45356f54nilgun * SUCH DAMAGE.
e609c337f729875bc20e01096c7e610f45356f54nilgun * ====================================================================
e609c337f729875bc20e01096c7e610f45356f54nilgun * This software consists of voluntary contributions made by many
e609c337f729875bc20e01096c7e610f45356f54nilgun * individuals on behalf of the Apache Software Foundation. For more
e609c337f729875bc20e01096c7e610f45356f54nilgun * information on the Apache Software Foundation, please see
e609c337f729875bc20e01096c7e610f45356f54nilgun * Portions of this software are based upon public domain software
e609c337f729875bc20e01096c7e610f45356f54nilgun * originally written at the National Center for Supercomputing Applications,
e609c337f729875bc20e01096c7e610f45356f54nilgun * University of Illinois, Urbana-Champaign.
e609c337f729875bc20e01096c7e610f45356f54nilgunextern "C" {
e609c337f729875bc20e01096c7e610f45356f54nilgun * @package HTTP protocol handling
e609c337f729875bc20e01096c7e610f45356f54nilgun/* This is an optimization. We keep a record of the filter_rec that
e609c337f729875bc20e01096c7e610f45356f54nilgun * stores the old_write filter, so that we can avoid strcmp's later.
e609c337f729875bc20e01096c7e610f45356f54nilgunAP_DECLARE_DATA extern ap_filter_rec_t *ap_old_write_func;
e609c337f729875bc20e01096c7e610f45356f54nilgun * Prototypes for routines which either talk directly back to the user,
e609c337f729875bc20e01096c7e610f45356f54nilgun * or control the ones that eventually do.
e609c337f729875bc20e01096c7e610f45356f54nilgun * Read a request and fill in the fields.
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param c The current connection
e609c337f729875bc20e01096c7e610f45356f54nilgun * @return The new request_rec
e609c337f729875bc20e01096c7e610f45356f54nilgun/* Finish up stuff after a request */
e609c337f729875bc20e01096c7e610f45356f54nilgun * Called at completion of sending the response. It sends the terminating
e609c337f729875bc20e01096c7e610f45356f54nilgun * protocol information.
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param r The current request
e609c337f729875bc20e01096c7e610f45356f54nilgun * @deffunc void ap_finalize_request_protocol(request_rec *r)
e609c337f729875bc20e01096c7e610f45356f54nilgunAP_DECLARE(void) ap_finalize_request_protocol(request_rec *r);
e609c337f729875bc20e01096c7e610f45356f54nilgun * Send error back to client.
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param r The current request
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param recursive_error last arg indicates error status in case we get
e609c337f729875bc20e01096c7e610f45356f54nilgun * an error in the process of trying to deal with an ErrorDocument
e609c337f729875bc20e01096c7e610f45356f54nilgun * to handle some other error. In that case, we print the default
e609c337f729875bc20e01096c7e610f45356f54nilgun * report for the first thing that went wrong, and more briefly report
e609c337f729875bc20e01096c7e610f45356f54nilgun * on the problem with the ErrorDocument.
e609c337f729875bc20e01096c7e610f45356f54nilgun * @deffunc void ap_send_error_response(request_rec *r, int recursive_error)
e609c337f729875bc20e01096c7e610f45356f54nilgunAP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error);
e609c337f729875bc20e01096c7e610f45356f54nilgun/* Set last modified header line from the lastmod date of the associated file.
e609c337f729875bc20e01096c7e610f45356f54nilgun * Also, set content length.
e609c337f729875bc20e01096c7e610f45356f54nilgun * May return an error status, typically HTTP_NOT_MODIFIED (that when the
e609c337f729875bc20e01096c7e610f45356f54nilgun * permit_cache argument is set to one).
e609c337f729875bc20e01096c7e610f45356f54nilgun * Set the content length for this request
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param r The current request
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param length The new content length
e609c337f729875bc20e01096c7e610f45356f54nilgun * @deffunc void ap_set_content_length(request_rec *r, apr_off_t length)
e609c337f729875bc20e01096c7e610f45356f54nilgunAP_DECLARE(void) ap_set_content_length(request_rec *r, apr_off_t length);
e609c337f729875bc20e01096c7e610f45356f54nilgun * Set the keepalive status for this request
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param r The current request
e609c337f729875bc20e01096c7e610f45356f54nilgun * @return 1 if keepalive can be set, 0 otherwise
e609c337f729875bc20e01096c7e610f45356f54nilgun * @deffunc int ap_set_keepalive(request_rec *r)
e609c337f729875bc20e01096c7e610f45356f54nilgun * Return the latest rational time from a request/mtime pair. Mtime is
e609c337f729875bc20e01096c7e610f45356f54nilgun * returned unless it's in the future, in which case we return the current time.
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param r The current request
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param mtime The last modified time
e609c337f729875bc20e01096c7e610f45356f54nilgun * @return the latest rational time.
e609c337f729875bc20e01096c7e610f45356f54nilgun * @deffunc apr_time_t ap_rationalize_mtime(request_rec *r, apr_time_t mtime)
e609c337f729875bc20e01096c7e610f45356f54nilgunAP_DECLARE(apr_time_t) ap_rationalize_mtime(request_rec *r, apr_time_t mtime);
e609c337f729875bc20e01096c7e610f45356f54nilgun * Build the content-type that should be sent to the client from the
e609c337f729875bc20e01096c7e610f45356f54nilgun * content-type specified. The following rules are followed:
e609c337f729875bc20e01096c7e610f45356f54nilgun * - if type is NULL, type is set to ap_default_type(r)
e609c337f729875bc20e01096c7e610f45356f54nilgun * - if charset adding is disabled, stop processing and return type.
e609c337f729875bc20e01096c7e610f45356f54nilgun * - then, if there are no parameters on type, add the default charset
e609c337f729875bc20e01096c7e610f45356f54nilgun * - return type
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param r The current request
e609c337f729875bc20e01096c7e610f45356f54nilgun * @return The content-type
e609c337f729875bc20e01096c7e610f45356f54nilgun * @deffunc const char *ap_make_content_type(request_rec *r, const char *type);
e609c337f729875bc20e01096c7e610f45356f54nilgunAP_DECLARE(const char *) ap_make_content_type(request_rec *r, const char *type);
e609c337f729875bc20e01096c7e610f45356f54nilgun * Construct an entity tag from the resource information. If it's a real
e609c337f729875bc20e01096c7e610f45356f54nilgun * file, build in some of the file characteristics.
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param r The current request
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param force_weak Force the entity tag to be weak - it could be modified
e609c337f729875bc20e01096c7e610f45356f54nilgun * again in as short an interval.
e609c337f729875bc20e01096c7e610f45356f54nilgun * @return The entity tag
e609c337f729875bc20e01096c7e610f45356f54nilgun * @deffunc char *ap_make_etag(request_rec *r, int force_weak)
e609c337f729875bc20e01096c7e610f45356f54nilgunAP_DECLARE(char *) ap_make_etag(request_rec *r, int force_weak);
e609c337f729875bc20e01096c7e610f45356f54nilgun * Set the E-tag outgoing header
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param The current request
e609c337f729875bc20e01096c7e610f45356f54nilgun * @deffunc void ap_set_etag(request_rec *r)
e609c337f729875bc20e01096c7e610f45356f54nilgun * Set the last modified time for the file being sent
91f378b5a10f2d83820902ed10ba7967a3920c18nilgun * @param r The current request
e609c337f729875bc20e01096c7e610f45356f54nilgun * @deffunc void ap_set_last_modified(request_rec *r)
e609c337f729875bc20e01096c7e610f45356f54nilgunAP_DECLARE(void) ap_set_last_modified(request_rec *r);
e609c337f729875bc20e01096c7e610f45356f54nilgun * Implements condition GET rules for HTTP/1.1 specification. This function
e609c337f729875bc20e01096c7e610f45356f54nilgun * inspects the client headers and determines if the response fulfills
e609c337f729875bc20e01096c7e610f45356f54nilgun * the requirements specified.
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param r The current request
91f378b5a10f2d83820902ed10ba7967a3920c18nilgun * @return 1 if the response fulfills the condition GET rules, 0 otherwise
91f378b5a10f2d83820902ed10ba7967a3920c18nilgun * @deffunc int ap_meets_conditions(request_rec *r)
e609c337f729875bc20e01096c7e610f45356f54nilgun/* Other ways to send stuff at the client. All of these keep track
e609c337f729875bc20e01096c7e610f45356f54nilgun * of bytes_sent automatically. This indirection is intended to make
e609c337f729875bc20e01096c7e610f45356f54nilgun * it a little more painless to slide things like HTTP-NG packetization
e609c337f729875bc20e01096c7e610f45356f54nilgun * underneath the main body of the code later. In the meantime, it lets
e609c337f729875bc20e01096c7e610f45356f54nilgun * us centralize a bit of accounting (bytes_sent).
e609c337f729875bc20e01096c7e610f45356f54nilgun * These also return the number of bytes written by the call.
e609c337f729875bc20e01096c7e610f45356f54nilgun * They should only be called with a timeout registered, for obvious reaasons.
e609c337f729875bc20e01096c7e610f45356f54nilgun * (Ditto the send_header stuff).
e609c337f729875bc20e01096c7e610f45356f54nilgun * Send an entire file to the client, using sendfile if supported by the
e609c337f729875bc20e01096c7e610f45356f54nilgun * current platform
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param fd The file to send.
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param r The current request
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param offset Offset into the file to start sending.
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param length Amount of data to send
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param nbytes Amount of data actually sent
e609c337f729875bc20e01096c7e610f45356f54nilgun * @deffunc apr_status_t ap_send_fd(apr_file_t *fd, request_rec *r, apr_off_t offset, apr_size_t length, apr_size_t *nbytes);
e609c337f729875bc20e01096c7e610f45356f54nilgunAP_DECLARE(apr_status_t) ap_send_fd(apr_file_t *fd, request_rec *r, apr_off_t offset,
e609c337f729875bc20e01096c7e610f45356f54nilgun * Send an MMAP'ed file to the client
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param mm The MMAP'ed file to send
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param r The current request
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param offset The offset into the MMAP to start sending
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param length The amount of data to send
e609c337f729875bc20e01096c7e610f45356f54nilgun * @return The number of bytes sent
e609c337f729875bc20e01096c7e610f45356f54nilgun * @deffunc size_t ap_send_mmap(apr_mmap_t *mm, request_rec *r, size_t offset, size_t length)
e609c337f729875bc20e01096c7e610f45356f54nilgunAP_DECLARE(size_t) ap_send_mmap(apr_mmap_t *mm, request_rec *r, size_t offset,
e609c337f729875bc20e01096c7e610f45356f54nilgun * Register a new request method, and return the offset that will be
e609c337f729875bc20e01096c7e610f45356f54nilgun * associated with that method.
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param p The pool to create registered method numbers from.
e609c337f729875bc20e01096c7e610f45356f54nilgun * @param methname The name of the new method to register.
e609c337f729875bc20e01096c7e610f45356f54nilgun * @return Ab int value representing an offset into a bitmask.
e609c337f729875bc20e01096c7e610f45356f54nilgunAP_DECLARE(int) ap_method_register(apr_pool_t *p, const char *methname);
e609c337f729875bc20e01096c7e610f45356f54nilgun * Initialize the method_registry and allocate memory for it.
int mnum),
void *rec,
int mnum),
const char *method);
* (only use outside protocol.c is in getting them configured).
struct ap_bucket_error {
int status;
const char *data;
* @deffunc apr_bucket *ap_bucket_error_make(apr_bucket *b, int error, const char *buf, apr_pool_t *p)
#ifdef __cplusplus