make custom 'Host' header a fatal exception
David Golden
9 years ago
0 | 0 |
Release notes for HTTP-Tiny
|
1 | 1 |
|
2 | 2 |
{{$NEXT}}
|
|
3 |
|
|
4 |
[CHANGED]
|
|
5 |
|
|
6 |
- Providing a custom 'Host' header is now a fatal exception. Previously, it
|
|
7 |
was silently ignored, as the RFC mandates that Host be set from the
|
|
8 |
URL, but ignoring it could lead to unexpected, confusing errors.
|
3 | 9 |
|
4 | 10 |
0.043 2014-02-20 20:40:23-05:00 America/New_York
|
5 | 11 |
|
322 | 322 |
A code reference that will be called for each chunks of the response
|
323 | 323 |
body received.
|
324 | 324 |
|
|
325 |
The C<Host> header is generated from the URL in accordance with RFC 2616. It
|
|
326 |
is a fatal error to specify C<Host> in the C<headers> option. Other headers
|
|
327 |
may be ignored or overwritten if necessary for transport compliance.
|
|
328 |
|
325 | 329 |
If the C<content> option is a code reference, it will be called iteratively
|
326 | 330 |
to provide the content body of the request. It should return the empty
|
327 | 331 |
string or undef when the iterator is exhausted.
|
|
640 | 644 |
$request->{headers}{lc $k} = $v;
|
641 | 645 |
}
|
642 | 646 |
}
|
|
647 |
|
|
648 |
if (exists $request->{headers}{'host'}) {
|
|
649 |
die(qq/The 'Host' header must not be provided as header option\n/);
|
|
650 |
}
|
|
651 |
|
643 | 652 |
$request->{headers}{'host'} = $request->{host_port};
|
644 | 653 |
$request->{headers}{'user-agent'} ||= $self->{agent};
|
645 | 654 |
$request->{headers}{'connection'} = "close"
|
34 | 34 |
like ($err, qr/\Q$usage{$method}\E/, join("|",@$c) );
|
35 | 35 |
}
|
36 | 36 |
|
|
37 |
my $res = $http->get("http://www.example.com/", { headers => { host => "www.example2.com" } } );
|
|
38 |
like( $res->{content}, qr/'Host' header/, "Providing a Host header is fatal" );
|
|
39 |
|
37 | 40 |
done_testing;
|
38 | 41 |
|