Browse files

Immitate Net::HTTP's removal of newlines from headers.

  • Loading branch information...
1 parent 1c77188 commit 54daf69d91df487eee4c045ebe36756f3f7ef1d2 @ikegami committed Nov 4, 2012
Showing with 54 additions and 1 deletion.
  1. +1 −1 Changes
  2. +1 −0 MANIFEST
  3. +1 −0 inc/Test/HTTP/LocalServer.pm
  4. +3 −0 inc/Test/HTTP/log-server
  5. +4 −0 lib/LWP/Protocol/AnyEvent/http.pm
  6. +44 −0 t/08_multiline_header.t
View
2 Changes
@@ -1,7 +1,7 @@
Revision history for LWP-Protocol-AnyEvent-http
1.0.6 xxxx-xx-xx
- - ...
+ - Immitate Net::HTTP's removal of newlines from headers.
1.0.5 2012-04.25
- Some test files were missing from MANIFEST.
View
1 MANIFEST
@@ -19,3 +19,4 @@ t/04_error_404.t
t/05_error_500_bogus_host.t
t/06_referer.t
t/07_proxy.t
+t/08_multiline_header.t
View
1 inc/Test/HTTP/LocalServer.pm
@@ -204,6 +204,7 @@ use vars qw(%urls);
'error_after_headers' => 'error/after_headers',
'chunked' => 'chunks',
'referer' => 'referer',
+ 'multiline_header' => 'multiline_header',
);
for (keys %urls) {
no strict 'refs';
View
3 inc/Test/HTTP/log-server
@@ -87,6 +87,9 @@ SERVERLOOP: {
} else {
$res = HTTP::Response->new(204);
}
+ } elsif ($location =~ m!^/multiline_header$!) {
+ $res = HTTP::Response->new(200);
+ $res->header('MultiLine', "foo\nbar");
} elsif ($location =~ m!^/error/after_headers$!) {
my $count = 2;
$res = HTTP::Response->new(200, "OK", undef, sub {
View
4 lib/LWP/Protocol/AnyEvent/http.pm
@@ -38,6 +38,10 @@ sub _set_response_headers {
];
}
+ # Immitate Net::HTTP's removal of newlines.
+ s/\s*\n\s+/ /g
+ for values %headers;
+
$response->header(%headers);
}
View
44 t/08_multiline_header.t
@@ -0,0 +1,44 @@
+#!perl -w
+use strict;
+use Test::More;
+
+use AnyEvent;
+use LWP::Protocol::AnyEvent::http;
+use LWP::UserAgent;
+
+# Check whether we can launch the local webserver
+if (! eval {
+ use lib '../inc', 'inc';
+ require Test::HTTP::LocalServer;
+ 1;
+}) {
+ plan skip_all => "Couldn't launch test server: $@";
+} else {
+ plan tests => 2;
+};
+
+# Launch a timer
+my $timer_events = 0;
+my $t = AnyEvent->timer(
+ after => 1, interval => 1, cb => sub { diag "Waiting for reply\n"; $timer_events++ }
+);
+
+my $client = LWP::UserAgent->new(requests_redirectable => []);
+
+my $server = Test::HTTP::LocalServer->spawn(
+ #debug => 1,
+);
+my $url = $server->multiline_header;
+diag "Retrieving URL: " . $url;
+
+my $res = $client->get($url);
+is $res->code, 200, "Request successful"
+ or diag($res->headers->as_string);
+is $res->header('MultiLine'), "foo bar", "Multiline header collapsed";
+
+undef $t; # stop the timer
+
+diag "Shutting down server";
+$server->stop;
+undef $server;
+diag "Done";

0 comments on commit 54daf69

Please sign in to comment.