diff --git a/Apewer/Web/ApiOptions.cs b/Apewer/Web/ApiOptions.cs
index 58f00fd..9fd1c25 100644
--- a/Apewer/Web/ApiOptions.cs
+++ b/Apewer/Web/ApiOptions.cs
@@ -26,6 +26,10 @@ namespace Apewer.Web
/// 默认值:不允许,响应空。
public bool AllowFavIcon { get; set; } = false;
+ /// 允许解析 OPTIONS 请求。
+ /// 默认值:不允许,直接返回 0 字节的 text/plain 内容。
+ public bool AllowOptions { get; set; } = false;
+
/// 允许解析 robots.txt 请求。
/// 默认值:不允许,拒绝搜索引擎收录根目录。
public bool AllowRobots { get; set; } = false;
diff --git a/Apewer/Web/ApiProcessor.cs b/Apewer/Web/ApiProcessor.cs
index 5a34d5d..781a795 100644
--- a/Apewer/Web/ApiProcessor.cs
+++ b/Apewer/Web/ApiProcessor.cs
@@ -92,9 +92,16 @@ namespace Apewer.Web
url = _context.Provider.GetUrl();
if (url == null) return "URL 无效。";
+ // Method
method = _context.Provider.GetMethod();
- if (method == HttpMethod.NULL) return "HTTP 方法无效。";
- if (method == HttpMethod.OPTIONS) return null;
+ switch (method)
+ {
+ case HttpMethod.NULL:
+ return "HTTP 方法无效。";
+ case HttpMethod.OPTIONS:
+ if (!_context.Options.AllowOptions) return null;
+ break;
+ }
// favicon.ico
var lowerPath = TextUtility.AssureStarts(TextUtility.Lower(url.AbsolutePath), "/");
@@ -127,8 +134,11 @@ namespace Apewer.Web
// OPTIONS
if (_context.Request.Method == HttpMethod.OPTIONS)
{
- _context.Response.Model = new ApiTextModel("");
- return;
+ if (!_context.Options.AllowOptions)
+ {
+ _context.Response.Model = new ApiTextModel("");
+ return;
+ }
}
// 路由