You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by wr...@apache.org on 2016/08/04 20:46:45 UTC
svn commit: r1755233 - /httpd/httpd/trunk/server/protocol.c
Author: wrowe
Date: Thu Aug 4 20:46:45 2016
New Revision: 1755233
URL: http://svn.apache.org/viewvc?rev=1755233&view=rev
Log:
As promised, reduce this logic by net 9 code lines, shifting the burden
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.
Modified:
httpd/httpd/trunk/server/protocol.c
Modified: httpd/httpd/trunk/server/protocol.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/protocol.c?rev=1755233&r1=1755232&r2=1755233&view=diff
==============================================================================
--- httpd/httpd/trunk/server/protocol.c (original)
+++ httpd/httpd/trunk/server/protocol.c Thu Aug 4 20:46:45 2016
@@ -834,7 +834,16 @@ AP_DECLARE(void) ap_get_mime_headers_cor
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_cor
&& (*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_cor
/* 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