1 package Catty::Controller::Root;
5 use base qw/ Catalyst::Controller /;
11 __PACKAGE__->config( namespace => '' );
13 sub default : Private {
14 my ( $self, $context ) = @_;
15 my $html = html( "Root", "This is the root page" );
16 $context->response->content_type("text/html");
17 $context->response->output($html);
21 my ( $self, $context ) = @_;
22 my $str = Encode::encode('utf-8', "\x{263A}"); # ☺
23 my $html = html( "Hello", "Hi there! $str" );
24 $context->response->content_type("text/html; charset=utf-8");
25 $context->response->output($html);
30 my ( $self, $context ) = @_;
31 my $where = $context->uri_for('hello');
32 $context->response->redirect($where);
36 # partial (relative) redirect
37 sub greetings : Global {
38 my ( $self, $context ) = @_;
39 $context->response->redirect("hello");
43 # redirect to a redirect
44 sub bonjour : Global {
45 my ( $self, $context ) = @_;
46 my $where = $context->uri_for('hi');
47 $context->response->redirect($where);
51 sub check_auth_basic : Global {
52 my ( $self, $context ) = @_;
54 my $auth = $context->req->headers->authorization;
55 ($auth) = $auth =~ /Basic\s(.*)/i;
56 $auth = decode_base64($auth);
58 if ( $auth eq "user:pass" ) {
59 my $html = html( "Auth", "This is the auth page" );
60 $context->response->content_type("text/html");
61 $context->response->output($html);
64 my $html = html( "Auth", "Auth Failed!" );
65 $context->response->content_type("text/html");
66 $context->response->output($html);
67 $context->response->status("401");
72 sub redirect_with_500 : Global {
73 my ( $self, $c ) = @_;
75 $c->res->redirect( $c->uri_for("/bonjour"));
80 my ( $self, $context ) = @_;
81 my $html = html( "Die", "This is the die page" );
82 $context->response->content_type("text/html");
83 $context->response->output($html);
90 my $html = html( $c->config->{name}, "This is the die page" );
91 $c->response->content_type("text/html");
92 $c->response->output($html);
98 my $host = $c->req->header('Host') || "<undef>";
99 my $html = html( $c->config->{name}, "Host: $host" );
100 $c->response->content_type("text/html");
101 $c->response->output($html);
105 my ( $title, $body ) = @_;
108 <head><title>$title</title></head>
111 <a href="/hello/">Hello</a>.
116 sub gzipped : Global {
117 my ( $self, $c ) = @_;
119 # If done properly this test should check the accept-encoding header, but we
120 # control both ends, so just always gzip the response.
121 require Compress::Zlib;
123 my $html = html( "Hello", "Hi there! ☺" );
124 $c->response->content_type("text/html; charset=utf-8");
125 $c->response->output( Compress::Zlib::memGzip($html) );
126 $c->response->content_encoding('gzip');
127 $c->response->headers->push_header( 'Vary', 'Accept-Encoding' );
130 sub user_agent : Global {
131 my ( $self, $c ) = @_;
133 my $html = html($c->req->user_agent, $c->req->user_agent);
134 $c->response->content_type("text/html; charset=utf-8");
135 $c->response->output( $html );
139 # per https://rt.cpan.org/Ticket/Display.html?id=36442
140 sub bad_content_encoding :Global {
142 $c->res->content_encoding('duff');
143 $c->res->body('foo');
146 sub redirect_to_utf8_upgraded_string {
148 my $where = $c->uri_for('hello')->stringify;
149 utf8::upgrade($where);
150 $c->res->redirect($where);