framework
framework copied to clipboard
路由会自动响应options请求,即便定义了options请求也会自动响应,应该怎么关闭呢?
/**
* 默认URL解析
* @access public
* @param string $url URL地址
* @return Dispatch
*/
public function url(string $url): Dispatch
{
if ($this->request->method() == 'OPTIONS') {
// 自动响应options请求
return new Callback($this->request, $this->group, function () {
return Response::create('', 'html', 204)->header(['Allow' => 'GET, POST, PUT, DELETE']);
});
}
return new UrlDispatch($this->request, $this->group, $url);
}
如上面代码,框架爱会自动响应options请求,即便是定义了options的路由也无法处理:
Route::rule('/', function (Request $request) {
return View::fetch(App::getRootPath() . 'view/index.html');
});
Route::rule('/', function (Request $request) {
}, 'OPTIONS');
但是如果把options定义的路由放到第一个,就可以进入路由了:
Route::rule('/', function (Request $request) {
}, 'OPTIONS');
Route::rule('/', function (Request $request) {
return View::fetch(App::getRootPath() . 'view/index.html');
});
这样不合适把,如果明确的定义了options的路由,无论什么时候定义的,都应该能进入路由吧。