default => 0
);
+has host => (
+ is => 'rw',
+ isa => 'Str',
+ clearer => 'clear_host',
+ predicate => 'has_host',
+);
+
sub new {
my $class = shift;
my ( $self, $request ) = @_;
$self->cookie_jar->add_cookie_header($request) if $self->cookie_jar;
+ my $uri = $request->uri;
+ if ($uri->as_string =~ m{^/}) {
+ $uri->scheme('http');
+ $uri->host('localhost');
+ }
+
+ # If there's no Host header, set one.
+ unless ($request->header('Host')) {
+ my $host = $self->has_host
+ ? $self->host
+ : $uri->host;
+
+ $request->header('Host', $host);
+ }
+
if ( $self->{allow_external} ) {
unless ( $request->uri->as_string =~ m{^/}
|| $request->uri->host eq 'localhost' )
}
}
- my $uri = $request->uri;
- if ($uri->as_string =~ m{^/}) {
- $uri->scheme('http');
- $uri->host('localhost');
- }
my @creds = $self->get_basic_credentials( "Basic", $uri );
$request->authorization_basic( @creds ) if @creds;
+
my $response = Catalyst::Test::local_request($self->{catalyst_app}, $request);
$response->header( 'Content-Base', $request->uri );
$response->request($request);
$m->allow_external(1);
+head2 catalyst_app
+
+The name of the Catalyst app which we are testing against. Read-only.
+
+=head2 host
+
+The host value to set the "Host:" HTTP header to, if none is present already in
+the request. If not set (default) then Catalyst::Test will set this to
+localhost:80
+
+=head2 clear_host
+
+Unset the host attribute.
+
+=head2 has_host
+
+Do we have a value set for the host attribute
+
=head2 $mech->get_ok($url, [ \%LWP_options ,] $desc)
A wrapper around WWW::Mechanize's get(), with similar options, except the
$c->response->output($html);
}
+sub host : Global {
+ my ($self, $c) = @_;
+
+ my $host = $c->req->header('Host') || "<undef>";
+ my $html = html( $c->config->{name}, "Host: $host" );
+ $c->response->content_type("text/html");
+ $c->response->output($html);
+}
+
sub html {
my ( $title, $body ) = @_;
return qq{