Codebase list libhttp-tiny-perl / 03dc86a
make custom 'Host' header a fatal exception David Golden 9 years ago
3 changed file(s) with 18 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
00 Release notes for HTTP-Tiny
11
22 {{$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.
39
410 0.043 2014-02-20 20:40:23-05:00 America/New_York
511
322322 A code reference that will be called for each chunks of the response
323323 body received.
324324
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
325329 If the C<content> option is a code reference, it will be called iteratively
326330 to provide the content body of the request. It should return the empty
327331 string or undef when the iterator is exhausted.
640644 $request->{headers}{lc $k} = $v;
641645 }
642646 }
647
648 if (exists $request->{headers}{'host'}) {
649 die(qq/The 'Host' header must not be provided as header option\n/);
650 }
651
643652 $request->{headers}{'host'} = $request->{host_port};
644653 $request->{headers}{'user-agent'} ||= $self->{agent};
645654 $request->{headers}{'connection'} = "close"
3434 like ($err, qr/\Q$usage{$method}\E/, join("|",@$c) );
3535 }
3636
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
3740 done_testing;
3841