output multiline %headers as multiple headers of the same name
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 29 May 2008 21:47:57 +0000 (21:47 +0000)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 31 May 2008 19:47:25 +0000 (19:47 +0000)
Allowing repeated HTTP headers (RFC2616 ยง4.2) even though this didn't
add much value afterall (one may also use commas).  It does prevent
(accidentally) malformed header values though, as most servers don't
seem to handle continuation lines.

Changes
TODO
lib/PLP.pm
lib/PLP/Fields.pm
lib/PLP/Functions.pm

diff --git a/Changes b/Changes
index 78da9d14c019e9a9f56c6e204ebabbc18085f2d7..30bd1b878b8cb8a5a91ff3e3bcd9411934f245ea 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,4 @@
+- %header values containing newlines will be sent as multiple fields
 - All modules use warnings and contain a $VERSION
 - Fix META.yml syntax
 
diff --git a/TODO b/TODO
index bd737512e21948f17004908c43050c1ab1af2cbb..508b2dcd37fe11741347f3dfff0f216f59ee40b1 100644 (file)
--- a/TODO
+++ b/TODO
@@ -2,7 +2,6 @@ In no particular order or significance:
 - lvalue %cookie (similar to AddCookie)
 - multipart posts [3.21]
 - install rules for servers
-- %header takes array ref
 - test plp parsing
 - redisplay include errors [3.21]
 - object instead of $PLP::
index 42866dc20f85d110662693e0c203a55faae94615..37d95b12e9cf8389a7967c4172f6cbdc72d44510 100644 (file)
@@ -94,7 +94,10 @@ sub handler {
 sub sendheaders () {
        $PLP::sentheaders ||= [ caller 1 ? (caller 1)[1, 2] : (caller)[1, 2] ];
        print STDOUT "Content-Type: text/plain\n\n" if $PLP::DEBUG & 2;
-       print STDOUT map("$_: $PLP::Script::header{$_}\n", keys %PLP::Script::header), "\n";
+       while (my ($header, $values) = each %PLP::Script::header) {
+               print STDOUT "$header: $_\n" for split /\n/, $values;
+       }
+       print STDOUT "\n";
 }
 
 {
index cd68e3655d6abf6d20c164d89fbcb8fed82383dc..212dec5c8e7486935cefd448bd48158458155299 100644 (file)
@@ -117,6 +117,10 @@ when sending the headers is the one you used first. The following are equal:
     $header{Content_Type}
     $headers{CONTENT_type}
 
+If a value contains newlines, the header is repeated for each line:
+
+       $header{Allow} = "HEAD\nGET";  # equivalent to HEAD,GET
+
 =back
 
 =head1 AUTHOR
index 90ff741453c213954362315a335d5579c1446515..f3621671470603b3f04f3dc086c57b22ca9ca09b 100644 (file)
@@ -75,7 +75,7 @@ sub EncodeURI (@) {
 
 sub AddCookie ($) {
        if ($PLP::Script::header{'Set-Cookie'}) {
-               $PLP::Script::header{'Set-Cookie'} .= "\nSet-Cookie: $_[0]";
+               $PLP::Script::header{'Set-Cookie'} .= "\n" . $_[0];
        } else {
                $PLP::Script::header{'Set-Cookie'} = $_[0];
        }