谁在默默处理 OPTIONS 与 HEAD 请求?视图函数会不会被执行?预检请求为什么会被鉴权拦掉?这篇用最小的例子把这些都实测出来。
OPTIONS /res → 200 OK | {'Content-Type': 'text/html; charset=utf-8', 'Allow': 'OPTIONS, GET, POST, HEAD', 'Content-Length': '0'} | 正文长度 0
这次请求触发的回调: ['before:OPTIONS']GET → 200 Content-Length 11 正文 11 HEAD → 200 Content-Length 11 正文 0 视图函数里记录到的方法: ['GET', 'HEAD']
OPTIONS /custom → 204 | Allow = GET, OPTIONS | X-Custom = 1
OPTIONS /noauto → 405 | Allow = GET, HEAD noauto 规则的 methods = ['GET', 'HEAD']
OPTIONS /res 触发的回调: ['before:OPTIONS']
→ 200 | {'Allow': 'OPTIONS, GET, POST, HEAD'}