1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef APACHE_HTTP_REQUEST_H
18 #define APACHE_HTTP_REQUEST_H
20 #include "apr_hooks.h"
21 #include "util_filter.h"
27 #define AP_SUBREQ_NO_ARGS 0
28 #define AP_SUBREQ_MERGE_ARGS 1
31 * @file http_request.h
32 * @brief Apache Request library
35 /* http_request.c is the code which handles the main line of request
36 * processing, once a request has been read in (finding the right per-
37 * directory configuration, building it if necessary, and calling all
38 * the module dispatch functions in the right order).
40 * The pieces here which are public to the modules, allow them to learn
41 * how the server would handle some other file or URI, or perhaps even
42 * direct the server to serve that other file instead of the one the
43 * client requested directly.
45 * There are two ways to do that. The first is the sub_request mechanism,
46 * which handles looking up files and URIs as adjuncts to some other
47 * request (e.g., directory entries for multiviews and directory listings);
48 * the lookup functions stop short of actually running the request, but
49 * (e.g., for includes), a module may call for the request to be run
50 * by calling run_sub_req. The space allocated to create sub_reqs can be
51 * reclaimed by calling destroy_sub_req --- be sure to copy anything you care
52 * about which was allocated in its apr_pool_t elsewhere before doing this.
56 * An internal handler used by the ap_process_request, all subrequest mechanisms
57 * and the redirect mechanism.
58 * @param r The request, subrequest or internal redirect to pre-process
59 * @return The return code for the request
61 AP_DECLARE(int) ap_process_request_internal(request_rec *r);
64 * Create a subrequest from the given URI. This subrequest can be
65 * inspected to find information about the requested URI
66 * @param new_uri The URI to lookup
67 * @param r The current request
68 * @param next_filter The first filter the sub_request should use. If this is
69 * NULL, it defaults to the first filter for the main request
70 * @return The new request record
71 * @deffunc request_rec * ap_sub_req_lookup_uri(const char *new_uri, const request_rec *r)
73 AP_DECLARE(request_rec *) ap_sub_req_lookup_uri(const char *new_uri,
75 ap_filter_t *next_filter);
78 * Create a subrequest for the given file. This subrequest can be
79 * inspected to find information about the requested file
80 * @param new_file The file to lookup
81 * @param r The current request
82 * @param next_filter The first filter the sub_request should use. If this is
83 * NULL, it defaults to the first filter for the main request
84 * @return The new request record
85 * @deffunc request_rec * ap_sub_req_lookup_file(const char *new_file, const request_rec *r)
87 AP_DECLARE(request_rec *) ap_sub_req_lookup_file(const char *new_file,
89 ap_filter_t *next_filter);
91 * Create a subrequest for the given apr_dir_read result. This subrequest
92 * can be inspected to find information about the requested file
93 * @param finfo The apr_dir_read result to lookup
94 * @param r The current request
95 * @param subtype What type of subrequest to perform, one of;
97 * AP_SUBREQ_NO_ARGS ignore r->args and r->path_info
98 * AP_SUBREQ_MERGE_ARGS merge r->args and r->path_info
100 * @param next_filter The first filter the sub_request should use. If this is
101 * NULL, it defaults to the first filter for the main request
102 * @return The new request record
103 * @deffunc request_rec * ap_sub_req_lookup_dirent(apr_finfo_t *finfo, int subtype, const request_rec *r)
104 * @tip The apr_dir_read flags value APR_FINFO_MIN|APR_FINFO_NAME flag is the
105 * minimum recommended query if the results will be passed to apr_dir_read.
106 * The file info passed must include the name, and must have the same relative
107 * directory as the current request.
109 AP_DECLARE(request_rec *) ap_sub_req_lookup_dirent(const apr_finfo_t *finfo,
110 const request_rec *r,
112 ap_filter_t *next_filter);
114 * Create a subrequest for the given URI using a specific method. This
115 * subrequest can be inspected to find information about the requested URI
116 * @param method The method to use in the new subrequest
117 * @param new_uri The URI to lookup
118 * @param r The current request
119 * @param next_filter The first filter the sub_request should use. If this is
120 * NULL, it defaults to the first filter for the main request
121 * @return The new request record
122 * @deffunc request_rec * ap_sub_req_method_uri(const char *method, const char *new_uri, const request_rec *r)
124 AP_DECLARE(request_rec *) ap_sub_req_method_uri(const char *method,
126 const request_rec *r,
127 ap_filter_t *next_filter);
129 * An output filter to strip EOS buckets from sub-requests. This always
130 * has to be inserted at the end of a sub-requests filter stack.
131 * @param f The current filter
132 * @param bb The brigade to filter
133 * @deffunc apr_status_t ap_sub_req_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
135 AP_CORE_DECLARE_NONSTD(apr_status_t) ap_sub_req_output_filter(ap_filter_t *f,
136 apr_bucket_brigade *bb);
139 * Run the handler for the subrequest
140 * @param r The subrequest to run
141 * @return The return code for the subrequest
142 * @deffunc int ap_run_sub_req(request_rec *r)
144 AP_DECLARE(int) ap_run_sub_req(request_rec *r);
147 * Free the memory associated with a subrequest
148 * @param r The subrequest to finish
149 * @deffunc void ap_destroy_sub_req(request_rec *r)
151 AP_DECLARE(void) ap_destroy_sub_req(request_rec *r);
154 * Then there's the case that you want some other request to be served
155 * as the top-level request INSTEAD of what the client requested directly.
156 * If so, call this from a handler, and then immediately return OK.
160 * Redirect the current request to some other uri
161 * @param new_uri The URI to replace the current request with
162 * @param r The current request
163 * @deffunc void ap_internal_redirect(const char *new_uri, request_rec *r)
165 AP_DECLARE(void) ap_internal_redirect(const char *new_uri, request_rec *r);
168 * This function is designed for things like actions or CGI scripts, when
169 * using AddHandler, and you want to preserve the content type across
170 * an internal redirect.
171 * @param new_uri The URI to replace the current request with.
172 * @param r The current request
173 * @deffunc void ap_internal_redirect_handler(const char *new_uri, request_rec *r)
175 AP_DECLARE(void) ap_internal_redirect_handler(const char *new_uri, request_rec *r);
178 * Redirect the current request to a sub_req, merging the pools
179 * @param sub_req A subrequest created from this request
180 * @param r The current request
181 * @deffunc void ap_internal_fast_redirect(request_rec *sub_req, request_rec *r)
182 * @tip the sub_req's pool will be merged into r's pool, be very careful
183 * not to destroy this subrequest, it will be destroyed with the main request!
185 AP_DECLARE(void) ap_internal_fast_redirect(request_rec *sub_req, request_rec *r);
188 * Can be used within any handler to determine if any authentication
189 * is required for the current request
190 * @param r The current request
191 * @return 1 if authentication is required, 0 otherwise
192 * @deffunc int ap_some_auth_required(request_rec *r)
194 AP_DECLARE(int) ap_some_auth_required(request_rec *r);
197 * Determine if the current request is the main request or a subrequest
198 * @param r The current request
199 * @return 1 if this is the main request, 0 otherwise
200 * @deffunc int ap_is_initial_req(request_rec *r)
202 AP_DECLARE(int) ap_is_initial_req(request_rec *r);
205 * Function to set the r->mtime field to the specified value if it's later
206 * than what's already there.
207 * @param r The current request
208 * @param dependency_time Time to set the mtime to
209 * @deffunc void ap_update_mtime(request_rec *r, apr_time_t dependency_mtime)
211 AP_DECLARE(void) ap_update_mtime(request_rec *r, apr_time_t dependency_mtime);
214 * Add one or more methods to the list permitted to access the resource.
215 * Usually executed by the content handler before the response header is
216 * sent, but sometimes invoked at an earlier phase if a module knows it
217 * can set the list authoritatively. Note that the methods are ADDED
218 * to any already permitted unless the reset flag is non-zero. The
219 * list is used to generate the Allow response header field when it
221 * @param r The pointer to the request identifying the resource.
222 * @param reset Boolean flag indicating whether this list should
223 * completely replace any current settings.
224 * @param ... A NULL-terminated list of strings, each identifying a
225 * method name to add.
227 * @deffunc void ap_allow_methods(request_rec *r, int reset, ...)
229 AP_DECLARE(void) ap_allow_methods(request_rec *r, int reset, ...);
232 * Add one or more methods to the list permitted to access the resource.
233 * Usually executed by the content handler before the response header is
234 * sent, but sometimes invoked at an earlier phase if a module knows it
235 * can set the list authoritatively. Note that the methods are ADDED
236 * to any already permitted unless the reset flag is non-zero. The
237 * list is used to generate the Allow response header field when it
239 * @param r The pointer to the request identifying the resource.
240 * @param reset Boolean flag indicating whether this list should
241 * completely replace any current settings.
242 * @param ... A list of method identifiers, from the "M_" series
243 * defined in httpd.h, terminated with a value of -1
244 * (e.g., "M_GET, M_POST, M_OPTIONS, -1")
246 * @deffunc void ap_allow_standard_methods(request_rec *r, int reset, ...)
248 AP_DECLARE(void) ap_allow_standard_methods(request_rec *r, int reset, ...);
250 #define MERGE_ALLOW 0
251 #define REPLACE_ALLOW 1
254 /* Function called by main.c to handle first-level request */
255 void ap_process_request(request_rec *);
257 * Kill the current request
258 * @param type Why the request is dieing
259 * @param r The current request
260 * @deffunc void ap_die(int type, request_rec *r)
262 AP_DECLARE(void) ap_die(int type, request_rec *r);
268 * Gives modules a chance to create their request_config entry when the
269 * request is created.
270 * @param r The current request
273 AP_DECLARE_HOOK(int,create_request,(request_rec *r))
276 * This hook allow modules an opportunity to translate the URI into an
277 * actual filename. If no modules do anything special, the server's default
278 * rules will be followed.
279 * @param r The current request
280 * @return OK, DECLINED, or HTTP_...
283 AP_DECLARE_HOOK(int,translate_name,(request_rec *r))
286 * This hook allow modules to set the per_dir_config based on their own
287 * context (such as <Proxy > sections) and responds to contextless requests
288 * such as TRACE that need no security or filesystem mapping.
289 * based on the filesystem.
290 * @param r The current request
291 * @return DONE (or HTTP_) if this contextless request was just fulfilled
292 * (such as TRACE), OK if this is not a file, and DECLINED if this is a file.
293 * The core map_to_storage (HOOK_RUN_REALLY_LAST) will directory_walk
294 * and file_walk the r->filename.
298 AP_DECLARE_HOOK(int,map_to_storage,(request_rec *r))
301 * This hook is used to analyze the request headers, authenticate the user,
302 * and set the user information in the request record (r->user and
303 * r->ap_auth_type). This hook is only run when Apache determines that
304 * authentication/authorization is required for this resource (as determined
305 * by the 'Require' directive). It runs after the access_checker hook, and
306 * before the auth_checker hook.
308 * @param r The current request
309 * @return OK, DECLINED, or HTTP_...
312 AP_DECLARE_HOOK(int,check_user_id,(request_rec *r))
315 * Allows modules to perform module-specific fixing of header fields. This
316 * is invoked just before any content-handler
317 * @param r The current request
318 * @return OK, DECLINED, or HTTP_...
321 AP_DECLARE_HOOK(int,fixups,(request_rec *r))
324 * This routine is called to determine and/or set the various document type
325 * information bits, like Content-type (via r->content_type), language, et
327 * @param r the current request
328 * @return OK, DECLINED, or HTTP_...
331 AP_DECLARE_HOOK(int,type_checker,(request_rec *r))
334 * This hook is used to apply additional access control to this resource.
335 * It runs *before* a user is authenticated, so this hook is really to
336 * apply additional restrictions independent of a user. It also runs
337 * independent of 'Require' directive usage.
339 * @param r the current request
340 * @return OK, DECLINED, or HTTP_...
343 AP_DECLARE_HOOK(int,access_checker,(request_rec *r))
346 * This hook is used to check to see if the resource being requested
347 * is available for the authenticated user (r->user and r->ap_auth_type).
348 * It runs after the access_checker and check_user_id hooks. Note that
349 * it will *only* be called if Apache determines that access control has
350 * been applied to this resource (through a 'Require' directive).
352 * @param r the current request
353 * @return OK, DECLINED, or HTTP_...
356 AP_DECLARE_HOOK(int,auth_checker,(request_rec *r))
359 * This hook allows modules to insert filters for the current request
360 * @param r the current request
363 AP_DECLARE_HOOK(void,insert_filter,(request_rec *r))
365 AP_DECLARE(int) ap_location_walk(request_rec *r);
366 AP_DECLARE(int) ap_directory_walk(request_rec *r);
367 AP_DECLARE(int) ap_file_walk(request_rec *r);
373 #endif /* !APACHE_HTTP_REQUEST_H */