4 use HTTP::Request::Common;
6 # Test cases for dispatching on URI Scheme
9 package MyApp::Controller::Root;
10 $INC{'MyApp/Controller/Root.pm'} = __FILE__;
12 use base 'Catalyst::Controller';
14 sub is_http :Path(scheme) Scheme(http) Args(0) {
16 Test::More::is $c->action->scheme, 'http';
17 $c->response->body("is_http");
20 sub is_https :Path(scheme) Scheme(https) Args(0) {
22 Test::More::is $c->action->scheme, 'https';
23 $c->response->body("is_https");
26 sub base :Chained('/') CaptureArgs(0) { }
28 sub is_http_chain :GET Chained('base') PathPart(scheme) Scheme(http) Args(0) {
30 Test::More::is $c->action->scheme, 'http';
31 $c->response->body("base/is_http");
34 sub is_https_chain :Chained('base') PathPart(scheme) Scheme(https) Args(0) {
36 Test::More::is $c->action->scheme, 'https';
37 $c->response->body("base/is_https");
40 sub uri_for1 :Chained('base') Scheme(https) Args(0) {
42 Test::More::is $c->action->scheme, 'https';
43 $c->response->body($c->uri_for($c->action)->as_string);
46 sub uri_for2 :Chained('base') Scheme(https) Args(0) {
48 Test::More::is $c->action->scheme, 'https';
49 $c->response->body($c->uri_for($self->action_for('is_http'))->as_string);
52 sub uri_for3 :Chained('base') Scheme(http) Args(0) {
54 Test::More::is $c->action->scheme, 'http';
55 $c->response->body($c->uri_for($self->action_for('endpoint'))->as_string);
58 sub base2 :Chained('/') CaptureArgs(0) { }
59 sub link :Chained(base2) Scheme(https) CaptureArgs(0) { }
60 sub endpoint :Chained(link) Args(0) {
62 Test::More::is $c->action->scheme, 'https';
63 $c->response->body("end");
70 Test::More::ok(MyApp->setup, 'setup app');
73 use Catalyst::Test 'MyApp';
76 my $res = request "/root/scheme";
77 is $res->code, 200, 'OK';
78 is $res->content, 'is_http', 'correct body';
82 my $res = request "https://localhost/root/scheme";
83 is $res->code, 200, 'OK';
84 is $res->content, 'is_https', 'correct body';
88 my $res = request "/base/scheme";
89 is $res->code, 200, 'OK';
90 is $res->content, 'base/is_http', 'correct body';
94 my $res = request "https://localhost/base/scheme";
95 is $res->code, 200, 'OK';
96 is $res->content, 'base/is_https', 'correct body';
100 my $res = request "https://localhost/base/uri_for1";
101 is $res->code, 200, 'OK';
102 is $res->content, 'https://localhost/base/uri_for1', 'correct body';
106 my $res = request "https://localhost/base/uri_for2";
107 is $res->code, 200, 'OK';
108 is $res->content, 'http://localhost/root/scheme', 'correct body';
112 my $res = request "/base/uri_for3";
113 is $res->code, 200, 'OK';
114 is $res->content, 'https://localhost/base2/link/endpoint', 'correct body';
118 my $res = request "https://localhost/base2/link/endpoint";
119 is $res->code, 200, 'OK';
120 is $res->content, 'end', 'correct body';