You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Brian Pane <bp...@pacbell.net> on 2001/09/06 17:50:58 UTC

[PATCH] optimization for setting of allowed methods

This patch eliminates some run-time conversion of method names to
numbers (something that I noticed while looking through function call
profiles).

--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/06 15:48:00
@@ -261,6 +261,24 @@
  */
 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 (M_GET, M_POST, etc)
+ * @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/06 15:48:00
@@ -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: server/core.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/core.c,v
retrieving revision 1.58
diff -u -r1.58 core.c
--- server/core.c    2001/08/31 13:45:16    1.58
+++ server/core.c    2001/09/06 15:48:02
@@ -2991,7 +2991,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;
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/06 15:48:04
@@ -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;
         }





Re: [PATCH] optimization for setting of allowed methods

Posted by Greg Marr <gr...@alum.wpi.edu>.
At 12:58 PM 09/06/2001, Ryan Bloom wrote:
>>  Weren't these "method numbers" recently removed so that there are 
>> no "standard" methods, and all the methods are added the same way 
>> at run time?
>
>In order to keep backwards compat, keep the patch small, and keep 
>the performance high for the standard HTTP methods, the old macros 
>were kept.  ... they are gauranteed to have the same value as the 
>constant though.

Ah, I missed that part of it.  Thanks.

-- 
Greg Marr
gregm@alum.wpi.edu
"We thought you were dead."
"I was, but I'm better now." - Sheridan, "The Summoning"


Re: [PATCH] optimization for setting of allowed methods

Posted by Brian Pane <bp...@pacbell.net>.
Ryan Bloom wrote:

>On Thursday 06 September 2001 09:29, Greg Marr wrote:
>
>>At 11:50 AM 09/06/2001, Brian Pane wrote:
>>
>>>This patch eliminates some run-time conversion of method names to
>>>numbers (something that I noticed while looking through function
>>>call profiles).
>>>
>>>RCS file: /home/cvspublic/httpd-2.0/server/core.c,v
>>>-    ap_allow_methods(r, MERGE_ALLOW, "GET", "OPTIONS", "POST", NULL);
>>>+    ap_allow_standard_methods(r, MERGE_ALLOW, M_GET, M_OPTIONS,
>>>M_POST, -1);
>>>
>>>RCS file:
>>>/home/cvspublic/httpd-2.0/modules/mappers/mod_negotiation.c,v
>>>-    ap_allow_methods(r, REPLACE_ALLOW, "GET", "OPTIONS", "POST",
>>>NULL);
>>>+    ap_allow_standard_methods(r, REPLACE_ALLOW, M_GET, M_OPTIONS,
>>>M_POST, -1);
>>>
>>Weren't these "method numbers" recently removed so that there are no
>>"standard" methods, and all the methods are added the same way at run
>>time?
>>
>
>Nope.  In order to keep backwards compat, keep the patch small, and keep the
>performance high for the standard HTTP methods, the old macros were kept.
>We just register them the same way we register extensions (they are gauranteed
>to have the same value as the constant though).
>
Cool.  Anybody willing to commit the patch?

Thanks,
--Brian




Re: [PATCH] optimization for setting of allowed methods

Posted by Ryan Bloom <rb...@covalent.net>.
On Thursday 06 September 2001 09:29, Greg Marr wrote:
> At 11:50 AM 09/06/2001, Brian Pane wrote:
> >This patch eliminates some run-time conversion of method names to
> >numbers (something that I noticed while looking through function
> >call profiles).
> >
> >RCS file: /home/cvspublic/httpd-2.0/server/core.c,v
> >-    ap_allow_methods(r, MERGE_ALLOW, "GET", "OPTIONS", "POST", NULL);
> >+    ap_allow_standard_methods(r, MERGE_ALLOW, M_GET, M_OPTIONS,
> >M_POST, -1);
> >
> >RCS file:
> >/home/cvspublic/httpd-2.0/modules/mappers/mod_negotiation.c,v
> >-    ap_allow_methods(r, REPLACE_ALLOW, "GET", "OPTIONS", "POST",
> >NULL);
> >+    ap_allow_standard_methods(r, REPLACE_ALLOW, M_GET, M_OPTIONS,
> >M_POST, -1);
>
> Weren't these "method numbers" recently removed so that there are no
> "standard" methods, and all the methods are added the same way at run
> time?

Nope.  In order to keep backwards compat, keep the patch small, and keep the
performance high for the standard HTTP methods, the old macros were kept.
We just register them the same way we register extensions (they are gauranteed
to have the same value as the constant though).

Ryan

______________________________________________________________
Ryan Bloom				rbb@apache.org
Covalent Technologies			rbb@covalent.net
--------------------------------------------------------------

Re: [PATCH] optimization for setting of allowed methods

Posted by Greg Marr <gr...@alum.wpi.edu>.
At 11:50 AM 09/06/2001, Brian Pane wrote:
>This patch eliminates some run-time conversion of method names to 
>numbers (something that I noticed while looking through function 
>call profiles).
>
>RCS file: /home/cvspublic/httpd-2.0/server/core.c,v
>-    ap_allow_methods(r, MERGE_ALLOW, "GET", "OPTIONS", "POST", NULL);
>+    ap_allow_standard_methods(r, MERGE_ALLOW, M_GET, M_OPTIONS, 
>M_POST, -1);
>
>RCS file: 
>/home/cvspublic/httpd-2.0/modules/mappers/mod_negotiation.c,v
>-    ap_allow_methods(r, REPLACE_ALLOW, "GET", "OPTIONS", "POST", 
>NULL);
>+    ap_allow_standard_methods(r, REPLACE_ALLOW, M_GET, M_OPTIONS, 
>M_POST, -1);

Weren't these "method numbers" recently removed so that there are no 
"standard" methods, and all the methods are added the same way at run 
time?

-- 
Greg Marr
gregm@alum.wpi.edu
"We thought you were dead."
"I was, but I'm better now." - Sheridan, "The Summoning"