http_protocol.h revision 666d616b7986a83bb0eac453694fbf4d6f05b98c
6ae232055d4d8a97267517c5e50074c2c819941and/* Copyright 1999-2004 The Apache Software Foundation
6ae232055d4d8a97267517c5e50074c2c819941and * Licensed under the Apache License, Version 2.0 (the "License");
6ae232055d4d8a97267517c5e50074c2c819941and * you may not use this file except in compliance with the License.
6ae232055d4d8a97267517c5e50074c2c819941and * You may obtain a copy of the License at
6ae232055d4d8a97267517c5e50074c2c819941and * Unless required by applicable law or agreed to in writing, software
6ae232055d4d8a97267517c5e50074c2c819941and * distributed under the License is distributed on an "AS IS" BASIS,
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * See the License for the specific language governing permissions and
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * limitations under the License.
b43f840409794ed298e8634f6284741f193b6c4ftakashiextern "C" {
b43f840409794ed298e8634f6284741f193b6c4ftakashi * @package HTTP protocol handling
6ae232055d4d8a97267517c5e50074c2c819941and * This hook allows modules to insert filters for the current error response
6ae232055d4d8a97267517c5e50074c2c819941and * @param r the current request
6ae232055d4d8a97267517c5e50074c2c819941and * @ingroup hooks
6ae232055d4d8a97267517c5e50074c2c819941andAP_DECLARE_HOOK(void,insert_error_filter,(request_rec *r))
6ae232055d4d8a97267517c5e50074c2c819941and/* This is an optimization. We keep a record of the filter_rec that
6ae232055d4d8a97267517c5e50074c2c819941and * stores the old_write filter, so that we can avoid strcmp's later.
6ae232055d4d8a97267517c5e50074c2c819941andAP_DECLARE_DATA extern ap_filter_rec_t *ap_old_write_func;
6ae232055d4d8a97267517c5e50074c2c819941and * Prototypes for routines which either talk directly back to the user,
6ae232055d4d8a97267517c5e50074c2c819941and * or control the ones that eventually do.
6ae232055d4d8a97267517c5e50074c2c819941and * Read a request and fill in the fields.
6ae232055d4d8a97267517c5e50074c2c819941and * @param c The current connection
6ae232055d4d8a97267517c5e50074c2c819941and * @return The new request_rec
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi * Read the mime-encoded headers.
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi * @param r The current request
6ae232055d4d8a97267517c5e50074c2c819941and * Optimized version of ap_get_mime_headers() that requires a
6ae232055d4d8a97267517c5e50074c2c819941and * temporary brigade to work with
6ae232055d4d8a97267517c5e50074c2c819941and * @param r The current request
6ae232055d4d8a97267517c5e50074c2c819941and * @param bb temp brigade
6ae232055d4d8a97267517c5e50074c2c819941and/* Finish up stuff after a request */
6ae232055d4d8a97267517c5e50074c2c819941and * Called at completion of sending the response. It sends the terminating
6ae232055d4d8a97267517c5e50074c2c819941and * protocol information.
6ae232055d4d8a97267517c5e50074c2c819941and * @param r The current request
6ae232055d4d8a97267517c5e50074c2c819941and * @deffunc void ap_finalize_request_protocol(request_rec *r)
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedoohAP_DECLARE(void) ap_finalize_request_protocol(request_rec *r);
6ae232055d4d8a97267517c5e50074c2c819941and * Send error back to client.
6ae232055d4d8a97267517c5e50074c2c819941and * @param r The current request
6ae232055d4d8a97267517c5e50074c2c819941and * @param recursive_error last arg indicates error status in case we get
6ae232055d4d8a97267517c5e50074c2c819941and * an error in the process of trying to deal with an ErrorDocument
6ae232055d4d8a97267517c5e50074c2c819941and * to handle some other error. In that case, we print the default
6ae232055d4d8a97267517c5e50074c2c819941and * report for the first thing that went wrong, and more briefly report
6ae232055d4d8a97267517c5e50074c2c819941and * on the problem with the ErrorDocument.
6ae232055d4d8a97267517c5e50074c2c819941and * @deffunc void ap_send_error_response(request_rec *r, int recursive_error)
6ae232055d4d8a97267517c5e50074c2c819941andAP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error);
6ae232055d4d8a97267517c5e50074c2c819941and/* Set last modified header line from the lastmod date of the associated file.
6ae232055d4d8a97267517c5e50074c2c819941and * Also, set content length.
6ae232055d4d8a97267517c5e50074c2c819941and * May return an error status, typically HTTP_NOT_MODIFIED (that when the
6ae232055d4d8a97267517c5e50074c2c819941and * permit_cache argument is set to one).
6ae232055d4d8a97267517c5e50074c2c819941and * Set the content length for this request
6ae232055d4d8a97267517c5e50074c2c819941and * @param r The current request
6ae232055d4d8a97267517c5e50074c2c819941and * @param length The new content length
6ae232055d4d8a97267517c5e50074c2c819941and * @deffunc void ap_set_content_length(request_rec *r, apr_off_t length)
6ae232055d4d8a97267517c5e50074c2c819941andAP_DECLARE(void) ap_set_content_length(request_rec *r, apr_off_t length);
6ae232055d4d8a97267517c5e50074c2c819941and * Set the keepalive status for this request
6ae232055d4d8a97267517c5e50074c2c819941and * @param r The current request
6ae232055d4d8a97267517c5e50074c2c819941and * @return 1 if keepalive can be set, 0 otherwise
6ae232055d4d8a97267517c5e50074c2c819941and * @deffunc int ap_set_keepalive(request_rec *r)
6ae232055d4d8a97267517c5e50074c2c819941and * Return the latest rational time from a request/mtime pair. Mtime is
6ae232055d4d8a97267517c5e50074c2c819941and * returned unless it's in the future, in which case we return the current time.
6ae232055d4d8a97267517c5e50074c2c819941and * @param r The current request
6ae232055d4d8a97267517c5e50074c2c819941and * @param mtime The last modified time
6ae232055d4d8a97267517c5e50074c2c819941and * @return the latest rational time.
6ae232055d4d8a97267517c5e50074c2c819941and * @deffunc apr_time_t ap_rationalize_mtime(request_rec *r, apr_time_t mtime)
6ae232055d4d8a97267517c5e50074c2c819941andAP_DECLARE(apr_time_t) ap_rationalize_mtime(request_rec *r, apr_time_t mtime);
6ae232055d4d8a97267517c5e50074c2c819941and * Build the content-type that should be sent to the client from the
6ae232055d4d8a97267517c5e50074c2c819941and * content-type specified. The following rules are followed:
6ae232055d4d8a97267517c5e50074c2c819941and * - if type is NULL, type is set to ap_default_type(r)
6ae232055d4d8a97267517c5e50074c2c819941and * - if charset adding is disabled, stop processing and return type.
6ae232055d4d8a97267517c5e50074c2c819941and * - then, if there are no parameters on type, add the default charset
6ae232055d4d8a97267517c5e50074c2c819941and * - return type
6ae232055d4d8a97267517c5e50074c2c819941and * @param r The current request
6ae232055d4d8a97267517c5e50074c2c819941and * @return The content-type
6ae232055d4d8a97267517c5e50074c2c819941and * @deffunc const char *ap_make_content_type(request_rec *r, const char *type);
6ae232055d4d8a97267517c5e50074c2c819941andAP_DECLARE(const char *) ap_make_content_type(request_rec *r,
6ae232055d4d8a97267517c5e50074c2c819941and const char *type);
6ae232055d4d8a97267517c5e50074c2c819941and * Precompile metadata structures used by ap_make_content_type()
6ae232055d4d8a97267517c5e50074c2c819941and * @param r The pool to use for allocations
6ae232055d4d8a97267517c5e50074c2c819941and * @deffunc void ap_setup_make_content_type(apr_pool_t *pool)
6ae232055d4d8a97267517c5e50074c2c819941andAP_DECLARE(void) ap_setup_make_content_type(apr_pool_t *pool);
6ae232055d4d8a97267517c5e50074c2c819941and#endif /* CORE_PRIVATE */
6ae232055d4d8a97267517c5e50074c2c819941and * Construct an entity tag from the resource information. If it's a real
6ae232055d4d8a97267517c5e50074c2c819941and * file, build in some of the file characteristics.
6ae232055d4d8a97267517c5e50074c2c819941and * @param r The current request
6ae232055d4d8a97267517c5e50074c2c819941and * @param force_weak Force the entity tag to be weak - it could be modified
6ae232055d4d8a97267517c5e50074c2c819941and * again in as short an interval.
6ae232055d4d8a97267517c5e50074c2c819941and * @return The entity tag
6ae232055d4d8a97267517c5e50074c2c819941and * @deffunc char *ap_make_etag(request_rec *r, int force_weak)
6ae232055d4d8a97267517c5e50074c2c819941andAP_DECLARE(char *) ap_make_etag(request_rec *r, int force_weak);
6ae232055d4d8a97267517c5e50074c2c819941and * Set the E-tag outgoing header
6ae232055d4d8a97267517c5e50074c2c819941and * @param The current request
6ae232055d4d8a97267517c5e50074c2c819941and * @deffunc void ap_set_etag(request_rec *r)
6ae232055d4d8a97267517c5e50074c2c819941and * Set the last modified time for the file being sent
6ae232055d4d8a97267517c5e50074c2c819941and * @param r The current request
6ae232055d4d8a97267517c5e50074c2c819941and * @deffunc void ap_set_last_modified(request_rec *r)
6ae232055d4d8a97267517c5e50074c2c819941and * Implements condition GET rules for HTTP/1.1 specification. This function
6ae232055d4d8a97267517c5e50074c2c819941and * inspects the client headers and determines if the response fulfills
6ae232055d4d8a97267517c5e50074c2c819941and * the requirements specified.
6ae232055d4d8a97267517c5e50074c2c819941and * @param r The current request
6ae232055d4d8a97267517c5e50074c2c819941and * @return OK if the response fulfills the condition GET rules, some
6ae232055d4d8a97267517c5e50074c2c819941and * other status code otherwise
6ae232055d4d8a97267517c5e50074c2c819941and * @deffunc int ap_meets_conditions(request_rec *r)
6ae232055d4d8a97267517c5e50074c2c819941and/* Other ways to send stuff at the client. All of these keep track
6ae232055d4d8a97267517c5e50074c2c819941and * of bytes_sent automatically. This indirection is intended to make
6ae232055d4d8a97267517c5e50074c2c819941and * it a little more painless to slide things like HTTP-NG packetization
6ae232055d4d8a97267517c5e50074c2c819941and * underneath the main body of the code later. In the meantime, it lets
6ae232055d4d8a97267517c5e50074c2c819941and * us centralize a bit of accounting (bytes_sent).
6ae232055d4d8a97267517c5e50074c2c819941and * These also return the number of bytes written by the call.
6ae232055d4d8a97267517c5e50074c2c819941and * They should only be called with a timeout registered, for obvious reaasons.
6ae232055d4d8a97267517c5e50074c2c819941and * (Ditto the send_header stuff).
6ae232055d4d8a97267517c5e50074c2c819941and * Send an entire file to the client, using sendfile if supported by the
6ae232055d4d8a97267517c5e50074c2c819941and * current platform
6ae232055d4d8a97267517c5e50074c2c819941and * @param fd The file to send.
6ae232055d4d8a97267517c5e50074c2c819941and * @param r The current request
6ae232055d4d8a97267517c5e50074c2c819941and * @param offset Offset into the file to start sending.
6ae232055d4d8a97267517c5e50074c2c819941and * @param length Amount of data to send
6ae232055d4d8a97267517c5e50074c2c819941and * @param nbytes Amount of data actually sent
6ae232055d4d8a97267517c5e50074c2c819941and * @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);
6ae232055d4d8a97267517c5e50074c2c819941andAP_DECLARE(apr_status_t) ap_send_fd(apr_file_t *fd, request_rec *r, apr_off_t offset,
6ae232055d4d8a97267517c5e50074c2c819941and * Send an MMAP'ed file to the client
6ae232055d4d8a97267517c5e50074c2c819941and * @param mm The MMAP'ed file to send
6ae232055d4d8a97267517c5e50074c2c819941and * @param r The current request
6ae232055d4d8a97267517c5e50074c2c819941and * @param offset The offset into the MMAP to start sending
6ae232055d4d8a97267517c5e50074c2c819941and * @param length The amount of data to send
6ae232055d4d8a97267517c5e50074c2c819941and * @return The number of bytes sent
6ae232055d4d8a97267517c5e50074c2c819941and * @deffunc size_t ap_send_mmap(apr_mmap_t *mm, request_rec *r, size_t offset, size_t length)
6ae232055d4d8a97267517c5e50074c2c819941andAP_DECLARE(size_t) ap_send_mmap(apr_mmap_t *mm, request_rec *r, size_t offset,
6ae232055d4d8a97267517c5e50074c2c819941and * Register a new request method, and return the offset that will be
6ae232055d4d8a97267517c5e50074c2c819941and * associated with that method.
6ae232055d4d8a97267517c5e50074c2c819941and * @param p The pool to create registered method numbers from.
6ae232055d4d8a97267517c5e50074c2c819941and * @param methname The name of the new method to register.
6ae232055d4d8a97267517c5e50074c2c819941and * @return Ab int value representing an offset into a bitmask.
6ae232055d4d8a97267517c5e50074c2c819941andAP_DECLARE(int) ap_method_register(apr_pool_t *p, const char *methname);
6ae232055d4d8a97267517c5e50074c2c819941and * Initialize the method_registry and allocate memory for it.
6ae232055d4d8a97267517c5e50074c2c819941and * @param p Pool to allocate memory for the registry from.
6ae232055d4d8a97267517c5e50074c2c819941and * This is a convenience macro to ease with checking a mask
6ae232055d4d8a97267517c5e50074c2c819941and * against a method name.
6ae232055d4d8a97267517c5e50074c2c819941and ((mask) & (AP_METHOD_BIT << ap_method_number_of((methname))))
6ae232055d4d8a97267517c5e50074c2c819941and * Create a new method list with the specified number of preallocated
b43f840409794ed298e8634f6284741f193b6c4ftakashi * slots for extension methods.
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung * @param p Pointer to a pool in which the structure should be
727872d18412fc021f03969b8641810d8896820bhumbedooh * allocated.
0d0ba3a410038e179b695446bb149cce6264e0abnd * @param nelts Number of preallocated extension slots
727872d18412fc021f03969b8641810d8896820bhumbedooh * @return Pointer to the newly created structure.
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh * @deffunc ap_method_list_t ap_make_method_list(apr_pool_t *p, int nelts)
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedoohAP_DECLARE(ap_method_list_t *) ap_make_method_list(apr_pool_t *p, int nelts);
727872d18412fc021f03969b8641810d8896820bhumbedoohAP_DECLARE(void) ap_copy_method_list(ap_method_list_t *dest,
0d0ba3a410038e179b695446bb149cce6264e0abndAP_DECLARE_NONSTD(void) ap_method_list_do(int (*comp) (void *urec, const char *mname,
0d0ba3a410038e179b695446bb149cce6264e0abndAP_DECLARE(void) ap_method_list_vdo(int (*comp) (void *urec, const char *mname,
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * Search for an HTTP method name in an ap_method_list_t structure, and
1a1356f375e36db7bee379ea0684ab389579f798rbowen * return true if found.
0d0ba3a410038e179b695446bb149cce6264e0abnd * @param method String containing the name of the method to check.
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd * @param l Pointer to a method list, such as cmd->methods_limited.
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd * @return 1 if method is in the list, otherwise 0
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd * @deffunc int ap_method_in_list(const char *method, ap_method_list_t *l)
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)
* @deffunc apr_bucket *ap_bucket_error_create(int error, const char *buf, apr_pool_t *p, apr_bucket_alloc_t *list)
apr_pool_t *p,
#ifdef __cplusplus