5 package t::Web::Simple::HTTPMethods;
8 use Web::Dispatch::HTTPMethods;
11 [200, ['Content-Type' => 'text/plain'],
12 [$_[0]->{REQUEST_METHOD}, $_[0]->{REQUEST_URI}] ]
15 sub dispatch_request {
19 sub (/get-head-options) {
22 OPTIONS { [204,[],[]] },
32 ok my $app = t::Web::Simple::HTTPMethods->new,
35 for my $uri ('http://localhost/get-post-put') {
37 ## Check allowed methods and responses
38 for(ok my $res = $app->run_test_request(GET => $uri)) {
39 is $res->content, 'GET/get-post-put';
42 for(ok my $res = $app->run_test_request(POST => $uri)) {
43 is $res->content, 'POST/get-post-put';
46 for(ok my $res = $app->run_test_request(PUT => $uri)) {
47 is $res->content, 'PUT/get-post-put';
50 ## Since GET is allowed, check for implict HEAD
51 for(ok my $head = $app->run_test_request(HEAD => $uri)) {
53 is $head->content, '';
56 ## Check the implicit support for OPTIONS
57 for(ok my $options = $app->run_test_request(OPTIONS => $uri)) {
58 is $options->code, 200;
59 is $options->content, '';
60 is $options->header('Allow'), 'GET,HEAD,POST,PUT,OPTIONS';
63 ## Check implicitly added not allowed
64 for(ok my $not_allowed = $app->run_test_request(DELETE => $uri)) {
65 is $not_allowed->code, 405;
66 is $not_allowed->content, 'Method Not Allowed';
67 is $not_allowed->header('Allow'), 'GET,HEAD,POST,PUT,OPTIONS';
72 for my $uri ('http://localhost/get-head-options') {
74 ## Check allowed methods and responses
75 for(ok my $res = $app->run_test_request(GET => $uri)) {
76 is $res->content, 'GET/get-head-options';
79 for(ok my $head = $app->run_test_request(HEAD => $uri)) {
81 is $head->content, '';
84 for(ok my $options = $app->run_test_request(OPTIONS => $uri)) {
85 is $options->code, 204;
86 is $options->content, '';
89 ## Check implicitly added not allowed
90 for(ok my $not_allowed = $app->run_test_request(PUT => $uri)) {
91 is $not_allowed->code, 405;
92 is $not_allowed->content, 'Method Not Allowed';
93 is $not_allowed->header('Allow'), 'GET,HEAD,OPTIONS';
98 for my $uri ('http://localhost/get') {
100 ## Check allowed methods and responses
101 for(ok my $res = $app->run_test_request(GET => $uri)) {
102 is $res->content, 'GET/get';
105 ## Check implicitly added not allowed
106 for(ok my $not_allowed = $app->run_test_request(PUT => $uri)) {
107 is $not_allowed->code, 405;
108 is $not_allowed->content, 'Method Not Allowed';
109 is $not_allowed->header('Allow'), 'GET,HEAD,OPTIONS';
112 ## Since GET is allowed, check for implict HEAD
113 for(ok my $head = $app->run_test_request(HEAD => $uri)) {
115 is $head->content, '';