[This is a repost of an uncommitted patch from a couple of weeks ago. I've updated it to work against the current code in CVS.] This patch eliminates the wasteful run-time conversion of method names from strings to numbers in places where the methods are known at compile time. --Brian
Index: include/http_request.h =================================================================== RCS file: /home/cvspublic/httpd-2.0/include/http_request.h,v retrieving revision 1.36 diff -u -r1.36 http_request.h --- include/http_request.h 2001/08/31 01:38:06 1.36 +++ include/http_request.h 2001/09/19 05:26:42 @@ -261,6 +261,25 @@ */ AP_DECLARE(void) ap_allow_methods(request_rec *r, int reset, ...); +/** + * Add one or more methods to the list permitted to access the resource. + * Usually executed by the content handler before the response header is + * sent, but sometimes invoked at an earlier phase if a module knows it + * can set the list authoritatively. Note that the methods are ADDED + * to any already permitted unless the reset flag is non-zero. The + * list is used to generate the Allow response header field when it + * is needed. + * @param r The pointer to the request identifying the resource. + * @param reset Boolean flag indicating whether this list should + * completely replace any current settings. + * @param ... A list of method identifiers, from the "M_" series + * defined in httpd.h, terminated with a value of -1 + * (e.g., "M_GET, M_POST, M_OPTIONS, -1") + * @return None. + * @deffunc void ap_allow_standard_methods(request_rec *r, int reset, ...) + */ +AP_DECLARE(void) ap_allow_standard_methods(request_rec *r, int reset, ...); + #define MERGE_ALLOW 0 #define REPLACE_ALLOW 1 Index: modules/http/http_request.c =================================================================== RCS file: /home/cvspublic/httpd-2.0/modules/http/http_request.c,v retrieving revision 1.113 diff -u -r1.113 http_request.c --- modules/http/http_request.c 2001/08/31 03:49:42 1.113 +++ modules/http/http_request.c 2001/09/19 05:26:42 @@ -490,3 +490,28 @@ ap_method_list_add(r->allowed_methods, method); } } + + +AP_DECLARE(void) ap_allow_standard_methods(request_rec *r, int reset, ...) +{ + int method; + va_list methods; + apr_int64_t mask; + + /* + * Get rid of any current settings if requested; not just the + * well-known methods but any extensions as well. + */ + if (reset) { + ap_clear_method_list(r->allowed_methods); + } + + mask = 0; + va_start(methods, reset); + while ((method = va_arg(methods, int)) != -1) { + mask |= (AP_METHOD_BIT << method); + } + va_end; + + r->allowed_methods->method_mask |= mask; +} Index: modules/mappers/mod_negotiation.c =================================================================== RCS file: /home/cvspublic/httpd-2.0/modules/mappers/mod_negotiation.c,v retrieving revision 1.81 diff -u -r1.81 mod_negotiation.c --- modules/mappers/mod_negotiation.c 2001/08/30 13:37:16 1.81 +++ modules/mappers/mod_negotiation.c 2001/09/19 05:26:44 @@ -2768,7 +2768,7 @@ apr_bucket_brigade *bb; apr_bucket *e; - ap_allow_methods(r, REPLACE_ALLOW, "GET", "OPTIONS", "POST", NULL); + ap_allow_standard_methods(r, REPLACE_ALLOW, M_GET, M_OPTIONS, M_POST, -1); if ((res = ap_discard_request_body(r)) != OK) { return res; } Index: server/core.c =================================================================== RCS file: /home/cvspublic/httpd-2.0/server/core.c,v retrieving revision 1.60 diff -u -r1.60 core.c --- server/core.c 2001/09/17 21:07:36 1.60 +++ server/core.c 2001/09/19 05:26:46 @@ -2676,7 +2676,7 @@ bld_content_md5 = (d->content_md5 & 1) && r->output_filters->frec->ftype != AP_FTYPE_CONTENT; - ap_allow_methods(r, MERGE_ALLOW, "GET", "OPTIONS", "POST", NULL); + ap_allow_standard_methods(r, MERGE_ALLOW, M_GET, M_OPTIONS, M_POST, -1); if ((errstatus = ap_discard_request_body(r)) != OK) { return errstatus;