Skip to content
Browse files

Allow Host header

  • Loading branch information...
1 parent d247cd8 commit db975489cfeb51f2318512d92e4ece52c6c65e84 @dragon3 dragon3 committed Jun 6, 2011
Showing with 37 additions and 1 deletion.
  1. +3 −1 lib/RPC/XML/Client.pm
  2. +34 −0 t/51_client_with_host_header.t
View
4 lib/RPC/XML/Client.pm
@@ -240,7 +240,9 @@ sub send_request ## no critic (ProhibitExcessComplexity)
# Start by setting up the request-clone for using in this instance
$reqclone = $self->request->clone;
- $reqclone->header(Host => URI->new($reqclone->uri)->host);
+ unless ($reqclone->header('Host')) {
+ $reqclone->header(Host => URI->new($reqclone->uri)->host);
+ }
$can_compress = $self->compress; # Avoid making 4+ calls to the method
if ($self->compress_requests and $can_compress and
$req->length >= $self->compress_thresh)
View
34 t/51_client_with_host_header.t
@@ -0,0 +1,34 @@
+use strict;
+use warnings;
+
+use HTTP::Request;
+use Test::More;
+
+sub clone_with_host_header {
+ my $req = shift;
+ my $reqclone = $req->clone;
+ unless ( $reqclone->header('Host') ) {
+ $reqclone->header( Host => URI->new( $reqclone->uri )->host );
+ }
+ return $reqclone;
+}
+
+subtest "without_host_header" => sub {
+ my $req = HTTP::Request->new( POST => 'http://example.com' );
+ ok( !$req->header('Host') );
+
+ my $reqclone = clone_with_host_header($req);
+ ok( $reqclone->header('Host'), 'example.com' );
+};
+
+subtest "with_host_hedar" => sub {
+ my $req = HTTP::Request->new( POST => 'http://example.com' );
+ ok( !$req->header('Host') );
+ $req->header( 'Host', 'google.com' );
+ is( $req->header('Host'), 'google.com' );
+
+ my $reqclone = clone_with_host_header($req);
+ ok( $reqclone->header('Host'), 'google.com' );
+};
+
+done_testing;

0 comments on commit db97548

Please sign in to comment.
Something went wrong with that request. Please try again.