1 package Catty::Controller::Root;
5 use base qw/ Catalyst::Controller /;
12 __PACKAGE__->config( namespace => '' );
14 sub default : Private {
15 my ( $self, $context ) = @_;
16 my $html = html( "Root", "This is the root page" );
17 $context->response->content_type("text/html");
18 $context->response->output($html);
22 my ( $self, $context ) = @_;
23 my $str = Encode::encode('utf-8', "\x{263A}"); # ☺
24 my $html = html( "Hello", "Hi there! $str" );
25 $context->response->content_type("text/html; charset=utf-8");
26 $context->response->output($html);
28 # Newer Catalyst auto encodes UTF8, but this test case is borked and expects
29 # broken utf8 behavior. We'll make a real UTF8 Test case separately.
30 $context->clear_encoding if $context->can('clear_encoding'); # Compat with upcoming Catalyst 5.90080
35 my ( $self, $context ) = @_;
36 my $where = $context->uri_for('hello');
37 $context->response->redirect($where);
41 # partial (relative) redirect
42 sub greetings : Global {
43 my ( $self, $context ) = @_;
44 $context->response->redirect("hello");
48 # redirect to a redirect
49 sub bonjour : Global {
50 my ( $self, $context ) = @_;
51 my $where = $context->uri_for('hi');
52 $context->response->redirect($where);
56 sub check_auth_basic : Global {
57 my ( $self, $context ) = @_;
59 my $auth = $context->req->headers->authorization;
60 ($auth) = $auth =~ /Basic\s(.*)/i;
61 $auth = decode_base64($auth);
63 if ( $auth eq "user:pass" ) {
64 my $html = html( "Auth", "This is the auth page" );
65 $context->response->content_type("text/html");
66 $context->response->output($html);
69 my $html = html( "Auth", "Auth Failed!" );
70 $context->response->content_type("text/html");
71 $context->response->output($html);
72 $context->response->status("401");
77 sub redirect_with_500 : Global {
78 my ( $self, $c ) = @_;
80 $c->res->redirect( $c->uri_for("/bonjour"));
85 my ( $self, $context ) = @_;
86 my $html = html( "Die", "This is the die page" );
87 $context->response->content_type("text/html");
88 $context->response->output($html);
95 my $html = html( $c->config->{name}, "This is the die page" );
96 $c->response->content_type("text/html");
97 $c->response->output($html);
103 my $host = $c->req->header('Host') || "<undef>";
104 my $html = html( $c->config->{name}, "Host: $host" );
105 $c->response->content_type("text/html");
106 $c->response->output($html);
110 my ( $title, $body ) = @_;
113 <head><title>$title</title></head>
116 <a href="/hello/">Hello</a>.
121 sub gzipped : Global {
122 my ( $self, $c ) = @_;
124 # If done properly this test should check the accept-encoding header, but we
125 # control both ends, so just always gzip the response.
126 require Compress::Zlib;
128 my $html = Encode::encode('UTF-8', html( "Hello", "Hi there! ☺" ));
129 $c->response->content_type("text/html; charset=utf-8");
130 $c->response->output( Compress::Zlib::memGzip($html) );
131 $c->response->content_encoding('gzip');
132 $c->response->headers->push_header( 'Vary', 'Accept-Encoding' );
135 sub user_agent : Global {
136 my ( $self, $c ) = @_;
138 my $html = html($c->req->user_agent, $c->req->user_agent);
139 $c->response->content_type("text/html; charset=utf-8");
140 $c->response->output( $html );
144 # per https://rt.cpan.org/Ticket/Display.html?id=36442
145 sub bad_content_encoding :Global {
147 $c->res->content_encoding('duff');
148 $c->res->body('foo');
151 sub redirect_to_utf8_upgraded_string : Global {
153 my $where = $c->uri_for('hello', 'müller')->as_string;
154 utf8::upgrade($where);
155 $c->res->redirect($where);