John Levon <[EMAIL PROTECTED]> writes:

>     The field-content does not include any leading or trailing LWS:
>    linear white space occurring before the first non-whitespace
>    character of the field-value or after the last non-whitespace
>    character of the field-value. Such leading or trailing LWS MAY be
>    removed without changing the semantics of the field value. Any LWS
>    that occurs between field-content MAY be replaced with a single SP
>    before interpreting the field value or forwarding the message
>    downstream.

Ok, how about this patch:

2002-01-14  Hrvoje Niksic  <[EMAIL PROTECTED]>

        * headers.c (header_get): Strip trailing whitespace from the
        header.

Index: src/headers.c
===================================================================
RCS file: /pack/anoncvs/wget/src/headers.c,v
retrieving revision 1.6
diff -u -r1.6 headers.c
--- src/headers.c       2001/11/16 19:57:43     1.6
+++ src/headers.c       2002/01/14 15:13:31
@@ -64,8 +64,8 @@
    as much memory as necessary for it to fit.  It need not contain a
    `:', thus you can use it to retrieve, say, HTTP status line.
 
-   The trailing CRLF or LF are stripped from the header, and it is
-   zero-terminated.   #### Is this well-behaved?  */
+   All trailing whitespace is stripped from the header, and it is
+   zero-terminated.  */
 int
 header_get (struct rbuf *rbuf, char **hdr, enum header_get_flags flags)
 {
@@ -101,11 +101,13 @@
                  if (next == '\t' || next == ' ')
                    continue;
                }
-             /* The header ends.  */
+
+             /* Strip trailing whitespace.  (*hdr)[i] is the newline;
+                decrement I until it points to the last available
+                whitespace.  */
+             while (i > 0 && ISSPACE ((*hdr)[i - 1]))
+               --i;
              (*hdr)[i] = '\0';
-             /* Get rid of '\r'.  */
-             if (i > 0 && (*hdr)[i - 1] == '\r')
-               (*hdr)[i - 1] = '\0';
              break;
            }
        }

Reply via email to