Permalink
Browse files

lwp-request -H didn't allow repeated headers

This also deal with whitespace before/after the header and and allow
a "User-Agent" value that ends with space to just have it prepended
to the regular value.
  • Loading branch information...
1 parent 308ca5c commit fb7a0545931c6b4be436811d097ab951a3b0b434 @gisle committed Oct 15, 2011
Showing with 9 additions and 3 deletions.
  1. +9 −3 bin/lwp-request
View
@@ -396,9 +396,15 @@ else {
$request = HTTP::Request->new($method);
$request->header('If-Modified-Since', $options{'i'}) if defined $options{'i'};
for my $user_header (@{ $options{'H'} || [] }) {
- my ($header_name, $header_value) = split /:\s*/, $user_header, 2;
- $request->header($header_name, $header_value);
- $ua->agent($header_value) if lc($header_name) eq "user-agent"; # Ugh!
+ my ($header_name, $header_value) = split /\s*:\s*/, $user_header, 2;
+ $header_name =~ s/^\s+//;
+ if (lc($header_name) eq "user-agent") {
+ $header_value .= $ua->agent if $header_value =~ /\s\z/;
+ $ua->agent($header_value);
+ }
+ else {
+ $request->push_header($header_name, $header_value);
+ }
}
#$request->header('Accept', '*/*');
if ($options{'c'}) { # will always be set for request that wants content

0 comments on commit fb7a054

Please sign in to comment.