Amon2::Lite (0.07)にて、post(あるいはget)が405 Method Not Allowedになるケース
自分のやり方が希有なケースなのかもしれないのと、pathを書き換えれば即対応もできる、という前提で。
今確認している限りだと、一つのPathでgetとpostの両方の処理を書くと、後に書いた方がうまくmatchされないという状態になっている。
131 if (my $p = $router->match($c->request->env)) { 132 if ($p->{method}) { 133 for my $method ( @{ $p->{method} } ) { 134 if ( $method eq $c->request->env->{REQUEST_METHOD} ) { 135 return $p->{code}->( $c, $p ); 136 } 137 } 138 } else { 139 return $p->{code}->( $c, $p ); 140 } 141 my $content = '405 Method Not Allowed'; 142 return $c->create_response( 143 405, 144 [ 145 'Content-Type' => 'text/plain; charset=utf-8', 146 'Content-Length' => length($content), 147 ], 148 [$content] 149 );
app.psgiで、
get '/login' => sub { shift->render('login.html') }; post '/login' => sub { my $c = shift; ... };
としたうえで/loginに対してpostリクエストを送り、132行目の$pをDumpさせると
$VAR1 = { 'method' => [ 'GET', 'HEAD' ], 'code' => sub { "DUMMY" } };
となる。
修正をかけるにしても、Router::Simpleのほうにmethodも確認するようにpatchをあてないとダメな気がしつつ、なんかめんどくさいのでpathを変更する形でapp.psgiを修正しちゃったほうが早い気もしつつ…。