httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ic...@apache.org
Subject svn commit: r1701178 - in /httpd/httpd/trunk: include/http_protocol.h server/protocol.c
Date Fri, 04 Sep 2015 08:52:15 GMT
Author: icing
Date: Fri Sep  4 08:52:15 2015
New Revision: 1701178

URL: http://svn.apache.org/r1701178
Log:
improvements in ap_select_protocol(), supplied by yann ylavic

Modified:
    httpd/httpd/trunk/include/http_protocol.h
    httpd/httpd/trunk/server/protocol.c

Modified: httpd/httpd/trunk/include/http_protocol.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/http_protocol.h?rev=1701178&r1=1701177&r2=1701178&view=diff
==============================================================================
--- httpd/httpd/trunk/include/http_protocol.h (original)
+++ httpd/httpd/trunk/include/http_protocol.h Fri Sep  4 08:52:15 2015
@@ -800,7 +800,7 @@ AP_DECLARE_HOOK(const char *,protocol_ge
  */
 AP_DECLARE(const char *) ap_select_protocol(conn_rec *c, request_rec *r, 
                                             server_rec *s,
-                                            apr_array_header_t *choices);
+                                            const apr_array_header_t *choices);
 
 /**
  * Perform the actual protocol switch. The protocol given must have been

Modified: httpd/httpd/trunk/server/protocol.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/protocol.c?rev=1701178&r1=1701177&r2=1701178&view=diff
==============================================================================
--- httpd/httpd/trunk/server/protocol.c (original)
+++ httpd/httpd/trunk/server/protocol.c Fri Sep  4 08:52:15 2015
@@ -1951,7 +1951,7 @@ AP_DECLARE(void) ap_send_interim_respons
  * Compare two protocol identifier. Result is similar to strcmp():
  * 0 gives same precedence, >0 means proto1 is preferred.
  */
-static int protocol_cmp(apr_array_header_t *preferences,
+static int protocol_cmp(const apr_array_header_t *preferences,
                         const char *proto1,
                         const char *proto2)
 {
@@ -1979,47 +1979,57 @@ AP_DECLARE(const char *) ap_get_protocol
 
 AP_DECLARE(const char *) ap_select_protocol(conn_rec *c, request_rec *r, 
                                             server_rec *s,
-                                            apr_array_header_t *choices)
+                                            const apr_array_header_t *choices)
 {
     apr_pool_t *pool = r? r->pool : c->pool;
     core_server_config *conf = ap_get_core_module_config(s->module_config);
-    const char *protocol = NULL, *existing = ap_get_protocol(c);
+    const char *protocol = NULL, *existing;
     apr_array_header_t *proposals;
 
     if (APLOGcdebug(c)) {
         const char *p = apr_array_pstrcat(pool, conf->protocols, ',');
         ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c, 
                       "select protocol from %s, choices=%s for server %s", 
-                      p, choices?
-                      apr_array_pstrcat(pool, choices, ',') : "NULL",
+                      p, apr_array_pstrcat(pool, choices, ','),
                       s->server_hostname);
     }
-    
-    proposals = apr_array_make(pool, choices? choices->nelts+1 : 5, 
-                               sizeof(char *));
+
+    if (conf->protocols->nelts <= 0) {
+        /* nothing configured, by default, we only allow http/1.1 here.
+         * For now...
+         */
+        if (ap_array_str_contains(choices, AP_PROTOCOL_HTTP1)) {
+            return AP_PROTOCOL_HTTP1;
+        }
+        else {
+            return NULL;
+        }
+    }
+
+    proposals = apr_array_make(pool, choices->nelts + 1, sizeof(char *));
     ap_run_protocol_propose(c, r, s, choices, proposals);
-    
+
+    /* If the existing protocol has not been proposed, but is a choice,
+     * add it to the proposals implicitly.
+     */
+    existing = ap_get_protocol(c);
+    if (!ap_array_str_contains(proposals, existing)
+        && ap_array_str_contains(choices, existing)) {
+        APR_ARRAY_PUSH(proposals, const char*) = existing;
+    }
+
     if (proposals->nelts > 0) {
         int i;
-        apr_array_header_t *prefs = NULL;
-        
+        const apr_array_header_t *prefs = NULL;
+
         /* Default for protocols_honor_order is 'on' or != 0 */
-        if (conf->protocols_honor_order == 0 && choices && choices->nelts
> 0) {
+        if (conf->protocols_honor_order == 0 && choices->nelts > 0) {
             prefs = choices;
         }
         else {
             prefs = conf->protocols;
         }
 
-        /* If the existing protocol has not been proposed, but is a choice,
-         * add it to the proposals implicitly.
-         */
-        if (choices 
-            && !ap_array_str_contains(proposals, existing) 
-            && ap_array_str_contains(choices, existing)) {
-            APR_ARRAY_PUSH(proposals, const char*) = existing;
-        }
-
         /* Select the most preferred protocol */
         if (APLOGcdebug(c)) {
             ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c, 
@@ -2028,31 +2038,16 @@ AP_DECLARE(const char *) ap_select_proto
                           apr_array_pstrcat(pool, prefs, ','),
                           apr_array_pstrcat(pool, conf->protocols, ','));
         }
-        if (conf->protocols->nelts <= 0) {
-            /* nothing configured, by default, we only allow http/1.1 here.
-             * For now...
-             */
-            return (ap_array_str_contains(proposals, AP_PROTOCOL_HTTP1)?
-                    AP_PROTOCOL_HTTP1 : NULL);
-        }
-        else {
-            for (i = 0; i < proposals->nelts; ++i) {
-                const char *p = APR_ARRAY_IDX(proposals, i, const char *);
-                if (conf->protocols->nelts <= 0 && !strcmp(AP_PROTOCOL_HTTP1,
p)) {
-                    /* nothing configured, by default, we only allow http/1.1 here.
-                     * For now...
-                     */
-                    continue;
-                }
-                if (!ap_array_str_contains(conf->protocols, p)) {
-                    /* not a configured protocol here */
-                    continue;
-                }
-                else if (!protocol 
-                         || (protocol_cmp(prefs, protocol, p) < 0)) {
-                    /* none selected yet or this one has preference */
-                    protocol = p;
-                }
+        for (i = 0; i < proposals->nelts; ++i) {
+            const char *p = APR_ARRAY_IDX(proposals, i, const char *);
+            if (!ap_array_str_contains(conf->protocols, p)) {
+                /* not a configured protocol here */
+                continue;
+            }
+            else if (!protocol 
+                     || (protocol_cmp(prefs, protocol, p) < 0)) {
+                /* none selected yet or this one has preference */
+                protocol = p;
             }
         }
     }



Mime
View raw message