From 4b924b1351d4a8ea42652533081a3ea62df110e4 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 29 May 2008 21:47:57 +0000 Subject: [PATCH] output multiline %headers as multiple headers of the same name MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 1 + TODO | 1 - lib/PLP.pm | 5 ++++- lib/PLP/Fields.pm | 4 ++++ lib/PLP/Functions.pm | 2 +- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index 78da9d1..30bd1b8 100644 --- 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 bd73751..508b2dc 100644 --- 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:: diff --git a/lib/PLP.pm b/lib/PLP.pm index 42866dc..37d95b1 100644 --- a/lib/PLP.pm +++ b/lib/PLP.pm @@ -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"; } { diff --git a/lib/PLP/Fields.pm b/lib/PLP/Fields.pm index cd68e36..212dec5 100644 --- a/lib/PLP/Fields.pm +++ b/lib/PLP/Fields.pm @@ -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 diff --git a/lib/PLP/Functions.pm b/lib/PLP/Functions.pm index 90ff741..f362167 100644 --- a/lib/PLP/Functions.pm +++ b/lib/PLP/Functions.pm @@ -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]; } -- 2.30.0