1 /* Copyright 1999-2004 The Apache Software Foundation
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #ifndef APACHE_HTTP_REQUEST_H
17 #define APACHE_HTTP_REQUEST_H
19 #include "apr_hooks.h"
20 #include "util_filter.h"
26 #define AP_SUBREQ_NO_ARGS 0
27 #define AP_SUBREQ_MERGE_ARGS 1
30 * @file http_request.h
31 * @brief Apache Request library
34 /* http_request.c is the code which handles the main line of request
35 * processing, once a request has been read in (finding the right per-
36 * directory configuration, building it if necessary, and calling all
37 * the module dispatch functions in the right order).
39 * The pieces here which are public to the modules, allow them to learn
40 * how the server would handle some other file or URI, or perhaps even
41 * direct the server to serve that other file instead of the one the
42 * client requested directly.
44 * There are two ways to do that. The first is the sub_request mechanism,
45 * which handles looking up files and URIs as adjuncts to some other
46 * request (e.g., directory entries for multiviews and directory listings);
47 * the lookup functions stop short of actually running the request, but
48 * (e.g., for includes), a module may call for the request to be run
49 * by calling run_sub_req. The space allocated to create sub_reqs can be
50 * reclaimed by calling destroy_sub_req --- be sure to copy anything you care
51 * about which was allocated in its apr_pool_t elsewhere before doing this.
55 * An internal handler used by the ap_process_request, all sub request mechanisms
56 * and the redirect mechanism.
57 * @param r The request, subrequest or internal redirect to pre-process
58 * @return The return code for the request
60 AP_DECLARE(int) ap_process_request_internal(request_rec *r);
63 * Create a sub request from the given URI. This sub request can be
64 * inspected to find information about the requested URI
65 * @param new_file The URI to lookup
66 * @param r The current request
67 * @param next_filter The first filter the sub_request should use. If this is
68 * NULL, it defaults to the first filter for the main request
69 * @return The new request record
70 * @deffunc request_rec * ap_sub_req_lookup_uri(const char *new_file, const request_rec *r)
72 AP_DECLARE(request_rec *) ap_sub_req_lookup_uri(const char *new_file,
74 ap_filter_t *next_filter);
77 * Create a sub request for the given file. This sub request can be
78 * inspected to find information about the requested file
79 * @param new_file The URI to lookup
80 * @param r The current request
81 * @param next_filter The first filter the sub_request should use. If this is
82 * NULL, it defaults to the first filter for the main request
83 * @return The new request record
84 * @deffunc request_rec * ap_sub_req_lookup_file(const char *new_file, const request_rec *r)
86 AP_DECLARE(request_rec *) ap_sub_req_lookup_file(const char *new_file,
88 ap_filter_t *next_filter);
90 * Create a sub request for the given apr_dir_read result. This sub request
91 * can be inspected to find information about the requested file
92 * @param finfo The apr_dir_read result to lookup
93 * @param r The current request
94 * @param subtype What type of subrequest to perform, one of;
96 * AP_SUBREQ_NO_ARGS ignore r->args and r->path_info
97 * AP_SUBREQ_MERGE_ARGS merge r->args and r->path_info
99 * @param next_filter The first filter the sub_request should use. If this is
100 * NULL, it defaults to the first filter for the main request
101 * @return The new request record
102 * @deffunc request_rec * ap_sub_req_lookup_dirent(apr_finfo_t *finfo, int subtype, const request_rec *r)
103 * @tip The apr_dir_read flags value APR_FINFO_MIN|APR_FINFO_NAME flag is the
104 * minimum recommended query if the results will be passed to apr_dir_read.
105 * The file info passed must include the name, and must have the same relative
106 * directory as the current request.
108 AP_DECLARE(request_rec *) ap_sub_req_lookup_dirent(const apr_finfo_t *finfo,
109 const request_rec *r,
111 ap_filter_t *next_filter);
113 * Create a sub request for the given URI using a specific method. This
114 * sub request can be inspected to find information about the requested URI
115 * @param method The method to use in the new sub request
116 * @param new_file The URI to lookup
117 * @param r The current request
118 * @param next_filter The first filter the sub_request should use. If this is
119 * NULL, it defaults to the first filter for the main request
120 * @return The new request record
121 * @deffunc request_rec * ap_sub_req_method_uri(const char *method, const char *new_file, const request_rec *r)
123 AP_DECLARE(request_rec *) ap_sub_req_method_uri(const char *method,
124 const char *new_file,
125 const request_rec *r,
126 ap_filter_t *next_filter);
128 * An output filter to strip EOS buckets from sub-requests. This always
129 * has to be inserted at the end of a sub-requests filter stack.
130 * @param f The current filter
131 * @param bb The brigade to filter
132 * @deffunc apr_status_t ap_sub_req_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
134 AP_CORE_DECLARE_NONSTD(apr_status_t) ap_sub_req_output_filter(ap_filter_t *f,
135 apr_bucket_brigade *bb);
138 * Run the handler for the sub request
139 * @param r The sub request to run
140 * @return The return code for the sub request
141 * @deffunc int ap_run_sub_req(request_rec *r)
143 AP_DECLARE(int) ap_run_sub_req(request_rec *r);
146 * Free the memory associated with a sub request
147 * @param r The sub request to finish
148 * @deffunc void ap_destroy_sub_req(request_rec *r)
150 AP_DECLARE(void) ap_destroy_sub_req(request_rec *r);
153 * Then there's the case that you want some other request to be served
154 * as the top-level request INSTEAD of what the client requested directly.
155 * If so, call this from a handler, and then immediately return OK.
159 * Redirect the current request to some other uri
160 * @param new_uri The URI to replace the current request with
161 * @param r The current request
162 * @deffunc void ap_internal_redirect(const char *new_uri, request_rec *r)
164 AP_DECLARE(void) ap_internal_redirect(const char *new_uri, request_rec *r);
167 * This function is designed for things like actions or CGI scripts, when
168 * using AddHandler, and you want to preserve the content type across
169 * an internal redirect.
170 * @param new_uri The URI to replace the current request with.
171 * @param r The current request
172 * @deffunc void ap_internal_redirect_handler(const char *new_uri, request_rec *r)
174 AP_DECLARE(void) ap_internal_redirect_handler(const char *new_uri, request_rec *r);
177 * Redirect the current request to a sub_req, merging the pools
178 * @param sub_req A subrequest created from this request
179 * @param r The current request
180 * @deffunc void ap_internal_fast_redirect(request_rec *sub_req, request_rec *r)
181 * @tip the sub_req's pool will be merged into r's pool, be very careful
182 * not to destroy this subrequest, it will be destroyed with the main request!
184 AP_DECLARE(void) ap_internal_fast_redirect(request_rec *sub_req, request_rec *r);
187 * Can be used within any handler to determine if any authentication
188 * is required for the current request
189 * @param r The current request
190 * @return 1 if authentication is required, 0 otherwise
191 * @deffunc int ap_some_auth_required(request_rec *r)
193 AP_DECLARE(int) ap_some_auth_required(request_rec *r);
196 * Determine if the current request is the main request or a sub requests
197 * @param r The current request
198 * @retrn 1 if this is a main request, 0 otherwise
199 * @deffunc int ap_is_initial_req(request_rec *r)
201 AP_DECLARE(int) ap_is_initial_req(request_rec *r);
204 * Function to set the r->mtime field to the specified value if it's later
205 * than what's already there.
206 * @param r The current request
207 * @param dependency_time Time to set the mtime to
208 * @deffunc void ap_update_mtime(request_rec *r, apr_time_t dependency_mtime)
210 AP_DECLARE(void) ap_update_mtime(request_rec *r, apr_time_t dependency_mtime);
213 * Add one or more methods to the list permitted to access the resource.
214 * Usually executed by the content handler before the response header is
215 * sent, but sometimes invoked at an earlier phase if a module knows it
216 * can set the list authoritatively. Note that the methods are ADDED
217 * to any already permitted unless the reset flag is non-zero. The
218 * list is used to generate the Allow response header field when it
220 * @param r The pointer to the request identifying the resource.
221 * @param reset Boolean flag indicating whether this list should
222 * completely replace any current settings.
223 * @param ... A NULL-terminated list of strings, each identifying a
224 * method name to add.
226 * @deffunc void ap_allow_methods(request_rec *r, int reset, ...)
228 AP_DECLARE(void) ap_allow_methods(request_rec *r, int reset, ...);
231 * Add one or more methods to the list permitted to access the resource.
232 * Usually executed by the content handler before the response header is
233 * sent, but sometimes invoked at an earlier phase if a module knows it
234 * can set the list authoritatively. Note that the methods are ADDED
235 * to any already permitted unless the reset flag is non-zero. The
236 * list is used to generate the Allow response header field when it
238 * @param r The pointer to the request identifying the resource.
239 * @param reset Boolean flag indicating whether this list should
240 * completely replace any current settings.
241 * @param ... A list of method identifiers, from the "M_" series
242 * defined in httpd.h, terminated with a value of -1
243 * (e.g., "M_GET, M_POST, M_OPTIONS, -1")
245 * @deffunc void ap_allow_standard_methods(request_rec *r, int reset, ...)
247 AP_DECLARE(void) ap_allow_standard_methods(request_rec *r, int reset, ...);
249 #define MERGE_ALLOW 0
250 #define REPLACE_ALLOW 1
253 /* Function called by main.c to handle first-level request */
254 void ap_process_request(request_rec *);
256 * Kill the current request
257 * @param type Why the request is dieing
258 * @param r The current request
259 * @deffunc void ap_die(int type, request_rec *r)
261 AP_DECLARE(void) ap_die(int type, request_rec *r);
267 * Gives modules a chance to create their request_config entry when the
268 * request is created.
269 * @param r The current request
272 AP_DECLARE_HOOK(int,create_request,(request_rec *r))
275 * This hook allow modules an opportunity to translate the URI into an
276 * actual filename. If no modules do anything special, the server's default
277 * rules will be followed.
278 * @param r The current request
279 * @return OK, DECLINED, or HTTP_...
282 AP_DECLARE_HOOK(int,translate_name,(request_rec *r))
285 * This hook allow modules to set the per_dir_config based on their own
286 * context (such as <Proxy > sections) and responds to contextless requests
287 * such as TRACE that need no security or filesystem mapping.
288 * based on the filesystem.
289 * @param r The current request
290 * @return DONE (or HTTP_) if this contextless request was just fulfilled
291 * (such as TRACE), OK if this is not a file, and DECLINED if this is a file.
292 * The core map_to_storage (HOOK_RUN_LAST) will directory_walk and file_walk
297 AP_DECLARE_HOOK(int,map_to_storage,(request_rec *r))
300 * This hook is used to analyze the request headers, authenticate the user,
301 * and set the user information in the request record (r->user and
302 * r->ap_auth_type). This hook is only run when Apache determines that
303 * authentication/authorization is required for this resource (as determined
304 * by the 'Require' directive). It runs after the access_checker hook, and
305 * before the auth_checker hook.
307 * @param r The current request
308 * @return OK, DECLINED, or HTTP_...
311 AP_DECLARE_HOOK(int,check_user_id,(request_rec *r))
314 * Allows modules to perform module-specific fixing of header fields. This
315 * is invoked just before any content-handler
316 * @param r The current request
317 * @return OK, DECLINED, or HTTP_...
320 AP_DECLARE_HOOK(int,fixups,(request_rec *r))
323 * This routine is called to determine and/or set the various document type
324 * information bits, like Content-type (via r->content_type), language, et
326 * @param r the current request
327 * @return OK, DECLINED, or HTTP_...
330 AP_DECLARE_HOOK(int,type_checker,(request_rec *r))
333 * This hook is used to apply additional access control to this resource.
334 * It runs *before* a user is authenticated, so this hook is really to
335 * apply additional restrictions independent of a user. It also runs
336 * independent of 'Require' directive usage.
338 * @param r the current request
339 * @return OK, DECLINED, or HTTP_...
342 AP_DECLARE_HOOK(int,access_checker,(request_rec *r))
345 * This hook is used to check to see if the resource being requested
346 * is available for the authenticated user (r->user and r->ap_auth_type).
347 * It runs after the access_checker and check_user_id hooks. Note that
348 * it will *only* be called if Apache determines that access control has
349 * been applied to this resource (through a 'Require' directive).
351 * @param r the current request
352 * @return OK, DECLINED, or HTTP_...
355 AP_DECLARE_HOOK(int,auth_checker,(request_rec *r))
358 * This hook allows modules to insert filters for the current request
359 * @param r the current request
362 AP_DECLARE_HOOK(void,insert_filter,(request_rec *r))
364 AP_DECLARE(int) ap_location_walk(request_rec *r);
365 AP_DECLARE(int) ap_directory_walk(request_rec *r);
366 AP_DECLARE(int) ap_file_walk(request_rec *r);
372 #endif /* !APACHE_HTTP_REQUEST_H */