using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Web;
namespace Apewer.Web
{
/// 选项。
public class ApiOptions
{
/// 限制最大请求的字节数。
/// 默认值:-1,不使用 ApiOptions 限制。
public long MaxRequestBody { get; set; } = -1;
/// 设置 Access-Control-Max-Age 的值。
/// 默认值:60。
public int AccessControlMaxAge { get; set; } = 60;
/// 允许解析 favicon.ico 请求。
/// 默认值:不允许,响应空。
public bool AllowFavIcon { get; set; } = false;
/// 允许解析 robots.txt 请求。
/// 默认值:不允许,拒绝搜索引擎收录根目录。
public bool AllowRobots { get; set; } = false;
/// 允许枚举输出 Applications 或 Functions。
/// 默认值:不允许,不输出列表。
public bool AllowEnumerate { get; set; } = false;
/// 允许输出的 Json 对象缩进。
/// 默认值:不缩进。
public bool JsonIndent { get; set; } = false;
/// 在响应头中设置 Content-Security-Policy,要求浏览器升级资源链接,使用 HTTPS。
/// 默认值:不要求。在 HTTPS 页面中,不自动升级 HTTP 资源。
public bool UpgradeHttps { get; set; } = false;
/// 允许响应中包含 Exception 对象的属性。
/// 默认值:不允许。
public bool WithException { get; set; } = false;
/// 允许输出 Application 列表时包含模块名称。
/// 默认值:不包含。
public bool WithModuleName { get; set; } = false;
/// 允许在枚举 Function 时包含参数信息。
/// 默认值:不包含。
public bool WithParameters { get; set; } = false;
/// 允许输出 Application 列表时包含类型名称。
/// 默认值:不包含。
public bool WithTypeName { get; set; } = false;
/// 在响应中包含时间属性。
/// 默认值:不包含。
public bool WithClock { get; set; } = false;
/// 在响应中包含执行 API 的持续时间。
/// 默认值:不包含。
public bool WithDuration { get; set; } = false;
/// 在响应中包含 Application 和 Function 属性。
/// 默认值:不包含。
public bool WithTarget { get; set; } = false;
/// 在响应中包含 Access-Control 属性。
/// 默认值:包含。
public bool WithAccessControl { get; set; } = true;
/// 允许响应标头中包含 X-Content-Type-Options: nosiff。
/// 默认值:不包含。当设置默认控制器时自动启用此属性。
public bool WithContentTypeOptions { get; set; } = false;
/// 允许同步 IO。
///
/// 默认值:允许。
/// 允许:使用同步方法写入 Response.Body,可能会导致线程不足而崩溃。
/// 不允许:必须用异步方法写入 Response.Body。
///
public bool AllowSynchronousIO { get; set; } = true;
#region 默认控制器,可用于静态控制器。
private Type _default = null;
/// 获取已设置的控制器类型,当未匹配到 Application 或 Function 时候,使用此类型创建控制器。
public Type Default { get => _default; }
/// 设置控制器类型,当未匹配到 Application 或 Function 时候,使用此类型创建控制器。
public void SetDefault() where T : ApiController, new() => _default = typeof(T);
/// 取消默认控制器类型。
public void SetDefault() => _default = null;
#endregion
/// 创建默认选项。
public ApiOptions()
{
Debug();
}
[Conditional("DEBUG")]
void Debug()
{
WithException = true;
}
}
}