Commit 01ebfa2c authored by Sören Kornetzki's avatar Sören Kornetzki

Issue #45 Empty HTTP header values causes "Invalid HTTP header field value" fatal

Added further checks to allow empty scalar/strings.
parent c5f07023
......@@ -1149,8 +1149,8 @@ sub write_header_lines {
$HeaderCase{lc $field_name} = $field_name;
}
for (ref $v eq 'ARRAY' ? @$v : $v) {
/[^\x0D\x0A]/
or die(qq/Invalid HTTP header field value ($field_name): / . $Printable->($_). "\n");
die(qq/Invalid HTTP header field value ($field_name): / . $Printable->($_). "\n")
if $_ ne '' && !$_ =~ m/[^\x0D\x0A]/;
$buf .= "$field_name: $_\x0D\x0A";
}
}
......
......@@ -49,3 +49,12 @@ use HTTP::Tiny;
is_deeply($handle->read_header_lines, $headers, "roundtrip header lines");
}
{
my $fh = tmpfile();
my $handle = HTTP::Tiny::Handle->new(fh => $fh);
my $headers = { foo => ['Foo', 'Baz'], bar => 'Bar', baz => '' };
$handle->write_header_lines($headers);
rewind($fh);
is_deeply($handle->read_header_lines, $headers, "roundtrip header lines");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment