]> granicus.if.org Git - apache/commitdiff
As promised, reduce this logic by net 9 code lines, shifting the burden
authorWilliam A. Rowe Jr <wrowe@apache.org>
Thu, 4 Aug 2016 20:46:45 +0000 (20:46 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Thu, 4 Aug 2016 20:46:45 +0000 (20:46 +0000)
of killing trailing whitespace to the purpose-agnostic read logic.

Whitespace before or after an obs-fold, and before or after a field value
have no semantic purpose at all. Because we are building a buffer for all
folded values, reducing the size of the newly allocated buffer is always
to our advantage.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1755233 13f79535-47bb-0310-9956-ffa450edef68

server/protocol.c

index 91577e378bfb7fa1b59ff53293d679894ea8e73b..524c9b4fd9a2de77564e3d338246eb27534e97c4 100644 (file)
@@ -834,7 +834,16 @@ AP_DECLARE(void) ap_get_mime_headers_core(request_rec *r, apr_bucket_brigade *bb
             return;
         }
 
-        if ((*field == '\t') || *field == ' ') {
+        /* For all header values, and all obs-fold lines, the presence of
+         * additional whitespace is a no-op, so collapse trailing whitespace
+         * to save buffer allocation and optimize copy operations.
+         * Do not remove the last single whitespace under any condition.
+         */
+        while (len > 1 && (field[len-1] == '\t' || field[len-1] == ' ')) {
+            field[--len] = '\0';
+        } 
+
+        if (*field == '\t' || *field == ' ') {
 
             /* Append any newly-read obs-fold line onto the preceding
              * last_field line we are processing
@@ -954,13 +963,6 @@ AP_DECLARE(void) ap_get_mime_headers_core(request_rec *r, apr_bucket_brigade *bb
                            && (*tmp_field == ' ' || *tmp_field == '\t')) {
                     *tmp_field-- = '\0';
                 }
-
-                /* Strip LWS after field-value: */
-                tmp_field = last_field + last_len - 1;
-                while (tmp_field > value
-                           && (*tmp_field == ' ' || *tmp_field == '\t')) {
-                    *tmp_field-- = '\0';
-                }
             }
             else /* Using strict RFC7230 parsing */
             {
@@ -990,15 +992,6 @@ AP_DECLARE(void) ap_get_mime_headers_core(request_rec *r, apr_bucket_brigade *bb
                 /* Find invalid, non-HT ctrl char, or the trailing NULL */
                 tmp_field = (char *)ap_scan_http_field_content(value);
 
-                /* Strip LWS after field-value, if string not empty */
-                if (*value && (*tmp_field == '\0')) {
-                    tmp_field--;
-                    while (*tmp_field == ' ' || *tmp_field == '\t') {
-                        *tmp_field-- = '\0';
-                    }
-                    ++tmp_field;
-                }
-
                 /* Reject value for all garbage input (CTRLs excluding HT)
                  * e.g. only VCHAR / SP / HT / obs-text are allowed per
                  * RFC7230 3.2.6 - leave all more explicit rule enforcement