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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 /*
18  * http_request.c: functions to get and process requests
19  *
20  * Rob McCool 3/21/93
21  *
22  * Thoroughly revamped by rst for Apache.  NB this file reads
23  * best from the bottom up.
24  *
25  */
26 
27 #include "apr_strings.h"
28 #include "apr_file_io.h"
29 #include "apr_fnmatch.h"
30 
31 #define APR_WANT_STRFUNC
32 #include "apr_want.h"
33 
34 #include "ap_config.h"
35 #include "httpd.h"
36 #include "http_config.h"
37 #include "http_request.h"
38 #include "http_core.h"
39 #include "http_protocol.h"
40 #include "http_log.h"
41 #include "http_main.h"
42 #include "util_filter.h"
43 #include "util_charset.h"
44 #include "scoreboard.h"
45 
46 #include "mod_core.h"
47 
48 #if APR_HAVE_STDARG_H
49 #include <stdarg.h>
50 #endif
51 
52 APLOG_USE_MODULE(http);
53 
54 /*****************************************************************
55  *
56  * Mainline request processing...
57  */
58 
59 /* XXX A cleaner and faster way to do this might be to pass the request_rec
60  * down the filter chain as a parameter.  It would need to change for
61  * subrequest vs. main request filters; perhaps the subrequest filter could
62  * make the switch.
63  */
update_r_in_filters(ap_filter_t * f,request_rec * from,request_rec * to)64 static void update_r_in_filters(ap_filter_t *f,
65                                 request_rec *from,
66                                 request_rec *to)
67 {
68     while (f) {
69         if (f->r == from) {
70             f->r = to;
71         }
72         f = f->next;
73     }
74 }
75 
ap_die(int type,request_rec * r)76 AP_DECLARE(void) ap_die(int type, request_rec *r)
77 {
78     int error_index = ap_index_of_response(type);
79     char *custom_response = ap_response_code_string(r, error_index);
80     int recursive_error = 0;
81     request_rec *r_1st_err = r;
82 
83     if (type == AP_FILTER_ERROR) {
84         ap_filter_t *next;
85 
86         /*
87          * Check if we still have the ap_http_header_filter in place. If
88          * this is the case we should not ignore AP_FILTER_ERROR here because
89          * it means that we have not sent any response at all and never
90          * will. This is bad. Sent an internal server error instead.
91          */
92         next = r->output_filters;
93         while (next && (next->frec != ap_http_header_filter_handle)) {
94                next = next->next;
95         }
96 
97         /*
98          * If next != NULL then we left the while above because of
99          * next->frec == ap_http_header_filter
100          */
101         if (next) {
102             ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01579)
103                           "Custom error page caused AP_FILTER_ERROR");
104             type = HTTP_INTERNAL_SERVER_ERROR;
105         }
106         else {
107             return;
108         }
109     }
110 
111     if (type == DONE) {
112         ap_finalize_request_protocol(r);
113         return;
114     }
115 
116     /*
117      * The following takes care of Apache redirects to custom response URLs
118      * Note that if we are already dealing with the response to some other
119      * error condition, we just report on the original error, and give up on
120      * any attempt to handle the other thing "intelligently"...
121      */
122     if (r->status != HTTP_OK) {
123         recursive_error = type;
124 
125         while (r_1st_err->prev && (r_1st_err->prev->status != HTTP_OK))
126             r_1st_err = r_1st_err->prev;  /* Get back to original error */
127 
128         if (r_1st_err != r) {
129             /* The recursive error was caused by an ErrorDocument specifying
130              * an internal redirect to a bad URI.  ap_internal_redirect has
131              * changed the filter chains to point to the ErrorDocument's
132              * request_rec.  Back out those changes so we can safely use the
133              * original failing request_rec to send the canned error message.
134              *
135              * ap_send_error_response gets rid of existing resource filters
136              * on the output side, so we can skip those.
137              */
138             update_r_in_filters(r_1st_err->proto_output_filters, r, r_1st_err);
139             update_r_in_filters(r_1st_err->input_filters, r, r_1st_err);
140         }
141 
142         custom_response = NULL; /* Do NOT retry the custom thing! */
143     }
144 
145     r->status = type;
146 
147     /*
148      * This test is done here so that none of the auth modules needs to know
149      * about proxy authentication.  They treat it like normal auth, and then
150      * we tweak the status.
151      */
152     if (HTTP_UNAUTHORIZED == r->status && PROXYREQ_PROXY == r->proxyreq) {
153         r->status = HTTP_PROXY_AUTHENTICATION_REQUIRED;
154     }
155 
156     /* If we don't want to keep the connection, make sure we mark that the
157      * connection is not eligible for keepalive.  If we want to keep the
158      * connection, be sure that the request body (if any) has been read.
159      */
160     if (ap_status_drops_connection(r->status)) {
161         r->connection->keepalive = AP_CONN_CLOSE;
162     }
163 
164     /*
165      * Two types of custom redirects --- plain text, and URLs. Plain text has
166      * a leading '"', so the URL code, here, is triggered on its absence
167      */
168 
169     if (custom_response && custom_response[0] != '"') {
170 
171         if (ap_is_url(custom_response)) {
172             /*
173              * The URL isn't local, so lets drop through the rest of this
174              * apache code, and continue with the usual REDIRECT handler.
175              * But note that the client will ultimately see the wrong
176              * status...
177              */
178             r->status = HTTP_MOVED_TEMPORARILY;
179             apr_table_setn(r->headers_out, "Location", custom_response);
180         }
181         else if (custom_response[0] == '/') {
182             const char *error_notes;
183             r->no_local_copy = 1;       /* Do NOT send HTTP_NOT_MODIFIED for
184                                          * error documents! */
185             /*
186              * This redirect needs to be a GET no matter what the original
187              * method was.
188              */
189             apr_table_setn(r->subprocess_env, "REQUEST_METHOD", r->method);
190 
191             /*
192              * Provide a special method for modules to communicate
193              * more informative (than the plain canned) messages to us.
194              * Propagate them to ErrorDocuments via the ERROR_NOTES variable:
195              */
196             if ((error_notes = apr_table_get(r->notes,
197                                              "error-notes")) != NULL) {
198                 apr_table_setn(r->subprocess_env, "ERROR_NOTES", error_notes);
199             }
200             r->method = "GET";
201             r->method_number = M_GET;
202             ap_internal_redirect(custom_response, r);
203             return;
204         }
205         else {
206             /*
207              * Dumb user has given us a bad url to redirect to --- fake up
208              * dying with a recursive server error...
209              */
210             recursive_error = HTTP_INTERNAL_SERVER_ERROR;
211             ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01580)
212                         "Invalid error redirection directive: %s",
213                         custom_response);
214         }
215     }
216     ap_send_error_response(r_1st_err, recursive_error);
217 }
218 
check_pipeline(conn_rec * c)219 static void check_pipeline(conn_rec *c)
220 {
221     if (c->keepalive != AP_CONN_CLOSE) {
222         apr_status_t rv;
223         apr_bucket_brigade *bb = apr_brigade_create(c->pool, c->bucket_alloc);
224 
225         rv = ap_get_brigade(c->input_filters, bb, AP_MODE_SPECULATIVE,
226                             APR_NONBLOCK_READ, 1);
227         if (rv != APR_SUCCESS || APR_BRIGADE_EMPTY(bb)) {
228             /*
229              * Error or empty brigade: There is no data present in the input
230              * filter
231              */
232             c->data_in_input_filters = 0;
233         }
234         else {
235             c->data_in_input_filters = 1;
236         }
237         apr_brigade_destroy(bb);
238     }
239 }
240 
241 
ap_process_request_after_handler(request_rec * r)242 AP_DECLARE(void) ap_process_request_after_handler(request_rec *r)
243 {
244     apr_bucket_brigade *bb;
245     apr_bucket *b;
246     conn_rec *c = r->connection;
247 
248     /* Send an EOR bucket through the output filter chain.  When
249      * this bucket is destroyed, the request will be logged and
250      * its pool will be freed
251      */
252     bb = apr_brigade_create(r->connection->pool, r->connection->bucket_alloc);
253     b = ap_bucket_eor_create(r->connection->bucket_alloc, r);
254     APR_BRIGADE_INSERT_HEAD(bb, b);
255 
256     ap_pass_brigade(r->connection->output_filters, bb);
257 
258     /* From here onward, it is no longer safe to reference r
259      * or r->pool, because r->pool may have been destroyed
260      * already by the EOR bucket's cleanup function.
261      */
262 
263     if (c->cs)
264         c->cs->state = CONN_STATE_WRITE_COMPLETION;
265     check_pipeline(c);
266     AP_PROCESS_REQUEST_RETURN((uintptr_t)r, r->uri, r->status);
267     if (ap_extended_status) {
268         ap_time_process_request(c->sbh, STOP_PREQUEST);
269     }
270 }
271 
ap_process_async_request(request_rec * r)272 void ap_process_async_request(request_rec *r)
273 {
274     conn_rec *c = r->connection;
275     int access_status;
276 
277     /* Give quick handlers a shot at serving the request on the fast
278      * path, bypassing all of the other Apache hooks.
279      *
280      * This hook was added to enable serving files out of a URI keyed
281      * content cache ( e.g., Mike Abbott's Quick Shortcut Cache,
282      * described here: http://oss.sgi.com/projects/apache/mod_qsc.html )
283      *
284      * It may have other uses as well, such as routing requests directly to
285      * content handlers that have the ability to grok HTTP and do their
286      * own access checking, etc (e.g. servlet engines).
287      *
288      * Use this hook with extreme care and only if you know what you are
289      * doing.
290      */
291     AP_PROCESS_REQUEST_ENTRY((uintptr_t)r, r->uri);
292     if (ap_extended_status) {
293         ap_time_process_request(r->connection->sbh, START_PREQUEST);
294     }
295 
296     if (APLOGrtrace4(r)) {
297         int i;
298         const apr_array_header_t *t_h = apr_table_elts(r->headers_in);
299         const apr_table_entry_t *t_elt = (apr_table_entry_t *)t_h->elts;
300         ap_log_rerror(APLOG_MARK, APLOG_TRACE4, 0, r,
301                       "Headers received from client:");
302         for (i = 0; i < t_h->nelts; i++, t_elt++) {
303             ap_log_rerror(APLOG_MARK, APLOG_TRACE4, 0, r, "  %s: %s",
304                           ap_escape_logitem(r->pool, t_elt->key),
305                           ap_escape_logitem(r->pool, t_elt->val));
306         }
307     }
308 
309 #if APR_HAS_THREADS
310     apr_thread_mutex_create(&r->invoke_mtx, APR_THREAD_MUTEX_DEFAULT, r->pool);
311     apr_thread_mutex_lock(r->invoke_mtx);
312 #endif
313     access_status = ap_run_quick_handler(r, 0);  /* Not a look-up request */
314     if (access_status == DECLINED) {
315         access_status = ap_process_request_internal(r);
316         if (access_status == OK) {
317             access_status = ap_invoke_handler(r);
318         }
319     }
320 
321     if (access_status == SUSPENDED) {
322         /* TODO: Should move these steps into a generic function, so modules
323          * working on a suspended request can also call _ENTRY again.
324          */
325         AP_PROCESS_REQUEST_RETURN((uintptr_t)r, r->uri, access_status);
326         if (ap_extended_status) {
327             ap_time_process_request(c->sbh, STOP_PREQUEST);
328         }
329         if (c->cs)
330             c->cs->state = CONN_STATE_SUSPENDED;
331 #if APR_HAS_THREADS
332         apr_thread_mutex_unlock(r->invoke_mtx);
333 #endif
334         return;
335     }
336 #if APR_HAS_THREADS
337     apr_thread_mutex_unlock(r->invoke_mtx);
338 #endif
339 
340     if (access_status == DONE) {
341         /* e.g., something not in storage like TRACE */
342         access_status = OK;
343     }
344 
345     if (access_status == OK) {
346         ap_finalize_request_protocol(r);
347     }
348     else {
349         r->status = HTTP_OK;
350         ap_die(access_status, r);
351     }
352 
353     ap_process_request_after_handler(r);
354 }
355 
ap_process_request(request_rec * r)356 void ap_process_request(request_rec *r)
357 {
358     apr_bucket_brigade *bb;
359     apr_bucket *b;
360     conn_rec *c = r->connection;
361     apr_status_t rv;
362 
363     ap_process_async_request(r);
364 
365     if (!c->data_in_input_filters) {
366         bb = apr_brigade_create(c->pool, c->bucket_alloc);
367         b = apr_bucket_flush_create(c->bucket_alloc);
368         APR_BRIGADE_INSERT_HEAD(bb, b);
369         rv = ap_pass_brigade(c->output_filters, bb);
370         if (APR_STATUS_IS_TIMEUP(rv)) {
371             /*
372              * Notice a timeout as an error message. This might be
373              * valuable for detecting clients with broken network
374              * connections or possible DoS attacks.
375              *
376              * It is still safe to use r / r->pool here as the eor bucket
377              * could not have been destroyed in the event of a timeout.
378              */
379             ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r, APLOGNO(01581)
380                           "Timeout while writing data for URI %s to the"
381                           " client", r->unparsed_uri);
382         }
383     }
384     if (ap_extended_status) {
385         ap_time_process_request(c->sbh, STOP_PREQUEST);
386     }
387 }
388 
rename_original_env(apr_pool_t * p,apr_table_t * t)389 static apr_table_t *rename_original_env(apr_pool_t *p, apr_table_t *t)
390 {
391     const apr_array_header_t *env_arr = apr_table_elts(t);
392     const apr_table_entry_t *elts = (const apr_table_entry_t *) env_arr->elts;
393     apr_table_t *new = apr_table_make(p, env_arr->nalloc);
394     int i;
395 
396     for (i = 0; i < env_arr->nelts; ++i) {
397         if (!elts[i].key)
398             continue;
399         apr_table_setn(new, apr_pstrcat(p, "REDIRECT_", elts[i].key, NULL),
400                   elts[i].val);
401     }
402 
403     return new;
404 }
405 
internal_internal_redirect(const char * new_uri,request_rec * r)406 static request_rec *internal_internal_redirect(const char *new_uri,
407                                                request_rec *r) {
408     int access_status;
409     request_rec *new;
410 
411     if (ap_is_recursion_limit_exceeded(r)) {
412         ap_die(HTTP_INTERNAL_SERVER_ERROR, r);
413         return NULL;
414     }
415 
416     new = (request_rec *) apr_pcalloc(r->pool, sizeof(request_rec));
417 
418     new->connection = r->connection;
419     new->server     = r->server;
420     new->pool       = r->pool;
421 
422     /*
423      * A whole lot of this really ought to be shared with http_protocol.c...
424      * another missing cleanup.  It's particularly inappropriate to be
425      * setting header_only, etc., here.
426      */
427 
428     new->method          = r->method;
429     new->method_number   = r->method_number;
430     new->allowed_methods = ap_make_method_list(new->pool, 2);
431     ap_parse_uri(new, new_uri);
432     new->parsed_uri.port_str = r->parsed_uri.port_str;
433     new->parsed_uri.port = r->parsed_uri.port;
434 
435     new->request_config = ap_create_request_config(r->pool);
436 
437     new->per_dir_config = r->server->lookup_defaults;
438 
439     new->prev = r;
440     r->next   = new;
441 
442     new->useragent_addr = r->useragent_addr;
443     new->useragent_ip = r->useragent_ip;
444 
445     /* Must have prev and next pointers set before calling create_request
446      * hook.
447      */
448     ap_run_create_request(new);
449 
450     /* Inherit the rest of the protocol info... */
451 
452     new->the_request = r->the_request;
453 
454     new->allowed         = r->allowed;
455 
456     new->status          = r->status;
457     new->assbackwards    = r->assbackwards;
458     new->header_only     = r->header_only;
459     new->protocol        = r->protocol;
460     new->proto_num       = r->proto_num;
461     new->hostname        = r->hostname;
462     new->request_time    = r->request_time;
463     new->main            = r->main;
464 
465     new->headers_in      = r->headers_in;
466     new->headers_out     = apr_table_make(r->pool, 12);
467     if (ap_is_HTTP_REDIRECT(new->status)) {
468         const char *location = apr_table_get(r->headers_out, "Location");
469         if (location)
470             apr_table_setn(new->headers_out, "Location", location);
471     }
472     new->err_headers_out = r->err_headers_out;
473     new->subprocess_env  = rename_original_env(r->pool, r->subprocess_env);
474     new->notes           = apr_table_make(r->pool, 5);
475 
476     new->htaccess        = r->htaccess;
477     new->no_cache        = r->no_cache;
478     new->expecting_100   = r->expecting_100;
479     new->no_local_copy   = r->no_local_copy;
480     new->read_length     = r->read_length;     /* We can only read it once */
481     new->vlist_validator = r->vlist_validator;
482 
483     new->proto_output_filters  = r->proto_output_filters;
484     new->proto_input_filters   = r->proto_input_filters;
485 
486     new->input_filters   = new->proto_input_filters;
487 
488     if (new->main) {
489         ap_filter_t *f, *nextf;
490 
491         /* If this is a subrequest, the filter chain may contain a
492          * mixture of filters specific to the old request (r), and
493          * some inherited from r->main.  Here, inherit that filter
494          * chain, and remove all those which are specific to the old
495          * request; ensuring the subreq filter is left in place. */
496         new->output_filters = r->output_filters;
497 
498         f = new->output_filters;
499         do {
500             nextf = f->next;
501 
502             if (f->r == r && f->frec != ap_subreq_core_filter_handle) {
503                 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01582)
504                               "dropping filter '%s' in internal redirect from %s to %s",
505                               f->frec->name, r->unparsed_uri, new_uri);
506 
507                 /* To remove the filter, first set f->r to the *new*
508                  * request_rec, so that ->output_filters on 'new' is
509                  * changed (if necessary) when removing the filter. */
510                 f->r = new;
511                 ap_remove_output_filter(f);
512             }
513 
514             f = nextf;
515 
516             /* Stop at the protocol filters.  If a protocol filter has
517              * been newly installed for this resource, better leave it
518              * in place, though it's probably a misconfiguration or
519              * filter bug to get into this state. */
520         } while (f && f != new->proto_output_filters);
521     }
522     else {
523         /* If this is not a subrequest, clear out all
524          * resource-specific filters. */
525         new->output_filters  = new->proto_output_filters;
526     }
527 
528     update_r_in_filters(new->input_filters, r, new);
529     update_r_in_filters(new->output_filters, r, new);
530 
531     apr_table_setn(new->subprocess_env, "REDIRECT_STATUS",
532                    apr_itoa(r->pool, r->status));
533 
534     /* Begin by presuming any module can make its own path_info assumptions,
535      * until some module interjects and changes the value.
536      */
537     new->used_path_info = AP_REQ_DEFAULT_PATH_INFO;
538 
539 #if APR_HAS_THREADS
540     new->invoke_mtx = r->invoke_mtx;
541 #endif
542 
543     /*
544      * XXX: hmm.  This is because mod_setenvif and mod_unique_id really need
545      * to do their thing on internal redirects as well.  Perhaps this is a
546      * misnamed function.
547      */
548     if ((access_status = ap_run_post_read_request(new))) {
549         ap_die(access_status, new);
550         return NULL;
551     }
552 
553     return new;
554 }
555 
556 /* XXX: Is this function is so bogus and fragile that we deep-6 it? */
ap_internal_fast_redirect(request_rec * rr,request_rec * r)557 AP_DECLARE(void) ap_internal_fast_redirect(request_rec *rr, request_rec *r)
558 {
559     /* We need to tell POOL_DEBUG that we're guaranteeing that rr->pool
560      * will exist as long as r->pool.  Otherwise we run into troubles because
561      * some values in this request will be allocated in r->pool, and others in
562      * rr->pool.
563      */
564     apr_pool_join(r->pool, rr->pool);
565     r->proxyreq = rr->proxyreq;
566     r->no_cache = (r->no_cache && rr->no_cache);
567     r->no_local_copy = (r->no_local_copy && rr->no_local_copy);
568     r->mtime = rr->mtime;
569     r->uri = rr->uri;
570     r->filename = rr->filename;
571     r->canonical_filename = rr->canonical_filename;
572     r->path_info = rr->path_info;
573     r->args = rr->args;
574     r->finfo = rr->finfo;
575     r->handler = rr->handler;
576     ap_set_content_type(r, rr->content_type);
577     r->content_encoding = rr->content_encoding;
578     r->content_languages = rr->content_languages;
579     r->per_dir_config = rr->per_dir_config;
580     /* copy output headers from subrequest, but leave negotiation headers */
581     r->notes = apr_table_overlay(r->pool, rr->notes, r->notes);
582     r->headers_out = apr_table_overlay(r->pool, rr->headers_out,
583                                        r->headers_out);
584     r->err_headers_out = apr_table_overlay(r->pool, rr->err_headers_out,
585                                            r->err_headers_out);
586     r->subprocess_env = apr_table_overlay(r->pool, rr->subprocess_env,
587                                           r->subprocess_env);
588 
589     r->output_filters = rr->output_filters;
590     r->input_filters = rr->input_filters;
591 
592     /* If any filters pointed at the now-defunct rr, we must point them
593      * at our "new" instance of r.  In particular, some of rr's structures
594      * will now be bogus (say rr->headers_out).  If a filter tried to modify
595      * their f->r structure when it is pointing to rr, the real request_rec
596      * will not get updated.  Fix that here.
597      */
598     update_r_in_filters(r->input_filters, rr, r);
599     update_r_in_filters(r->output_filters, rr, r);
600 
601     if (r->main) {
602         ap_add_output_filter_handle(ap_subreq_core_filter_handle,
603                                     NULL, r, r->connection);
604     }
605     else {
606         /*
607          * We need to check if we now have the SUBREQ_CORE filter in our filter
608          * chain. If this is the case we need to remove it since we are NO
609          * subrequest. But we need to keep in mind that the SUBREQ_CORE filter
610          * does not necessarily need to be the first filter in our chain. So we
611          * need to go through the chain. But we only need to walk up the chain
612          * until the proto_output_filters as the SUBREQ_CORE filter is below the
613          * protocol filters.
614          */
615         ap_filter_t *next;
616 
617         next = r->output_filters;
618         while (next && (next->frec != ap_subreq_core_filter_handle)
619                && (next != r->proto_output_filters)) {
620                 next = next->next;
621         }
622         if (next && (next->frec == ap_subreq_core_filter_handle)) {
623             ap_remove_output_filter(next);
624         }
625     }
626 }
627 
ap_internal_redirect(const char * new_uri,request_rec * r)628 AP_DECLARE(void) ap_internal_redirect(const char *new_uri, request_rec *r)
629 {
630     request_rec *new = internal_internal_redirect(new_uri, r);
631     int access_status;
632 
633     AP_INTERNAL_REDIRECT(r->uri, new_uri);
634 
635     /* ap_die was already called, if an error occured */
636     if (!new) {
637         return;
638     }
639 
640     access_status = ap_run_quick_handler(new, 0);  /* Not a look-up request */
641     if (access_status == DECLINED) {
642         access_status = ap_process_request_internal(new);
643         if (access_status == OK) {
644             access_status = ap_invoke_handler(new);
645         }
646     }
647     if (access_status == OK) {
648         ap_finalize_request_protocol(new);
649     }
650     else {
651         ap_die(access_status, new);
652     }
653 }
654 
655 /* This function is designed for things like actions or CGI scripts, when
656  * using AddHandler, and you want to preserve the content type across
657  * an internal redirect.
658  */
ap_internal_redirect_handler(const char * new_uri,request_rec * r)659 AP_DECLARE(void) ap_internal_redirect_handler(const char *new_uri, request_rec *r)
660 {
661     int access_status;
662     request_rec *new = internal_internal_redirect(new_uri, r);
663 
664     /* ap_die was already called, if an error occured */
665     if (!new) {
666         return;
667     }
668 
669     if (r->handler)
670         ap_set_content_type(new, r->content_type);
671     access_status = ap_process_request_internal(new);
672     if (access_status == OK) {
673         if ((access_status = ap_invoke_handler(new)) != 0) {
674             ap_die(access_status, new);
675             return;
676         }
677         ap_finalize_request_protocol(new);
678     }
679     else {
680         ap_die(access_status, new);
681     }
682 }
683 
ap_allow_methods(request_rec * r,int reset,...)684 AP_DECLARE(void) ap_allow_methods(request_rec *r, int reset, ...)
685 {
686     const char *method;
687     va_list methods;
688 
689     /*
690      * Get rid of any current settings if requested; not just the
691      * well-known methods but any extensions as well.
692      */
693     if (reset) {
694         ap_clear_method_list(r->allowed_methods);
695     }
696 
697     va_start(methods, reset);
698     while ((method = va_arg(methods, const char *)) != NULL) {
699         ap_method_list_add(r->allowed_methods, method);
700     }
701     va_end(methods);
702 }
703 
ap_allow_standard_methods(request_rec * r,int reset,...)704 AP_DECLARE(void) ap_allow_standard_methods(request_rec *r, int reset, ...)
705 {
706     int method;
707     va_list methods;
708     apr_int64_t mask;
709 
710     /*
711      * Get rid of any current settings if requested; not just the
712      * well-known methods but any extensions as well.
713      */
714     if (reset) {
715         ap_clear_method_list(r->allowed_methods);
716     }
717 
718     mask = 0;
719     va_start(methods, reset);
720     while ((method = va_arg(methods, int)) != -1) {
721         mask |= (AP_METHOD_BIT << method);
722     }
723     va_end(methods);
724 
725     r->allowed_methods->method_mask |= mask;
726 }
727