| | | 1 | | using Kestrun.Callback; |
| | | 2 | | using Kestrun.Utilities; |
| | | 3 | | |
| | | 4 | | namespace Kestrun.Hosting.Options; |
| | | 5 | | /// <summary> |
| | | 6 | | /// Options for mapping a route, including pattern, HTTP verbs, script code, authorization, and metadata. |
| | | 7 | | /// </summary> |
| | | 8 | | public class MapRouteOptions |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// The route pattern to match for this option. |
| | | 12 | | /// </summary> |
| | 568 | 13 | | public string? Pattern { get; set; } |
| | | 14 | | /// <summary> |
| | | 15 | | /// The HTTP verbs (methods) that this route responds to. |
| | | 16 | | /// </summary> |
| | 633 | 17 | | public List<HttpVerb> HttpVerbs { get; set; } = []; |
| | | 18 | | /// <summary> |
| | | 19 | | /// Authorization Scheme names required for this route. |
| | | 20 | | /// </summary> |
| | 328 | 21 | | public List<string> RequireSchemes { get; init; } = []; // Authorization scheme name, if any |
| | | 22 | | /// <summary> |
| | | 23 | | /// Authorization policy names required for this route. |
| | | 24 | | /// </summary> |
| | 312 | 25 | | public List<string> RequirePolicies { get; init; } = []; // Authorization policies, if any |
| | | 26 | | /// <summary> |
| | | 27 | | /// Name of the CORS policy to apply, if any. |
| | | 28 | | /// </summary> |
| | 268 | 29 | | public string CorsPolicy { get; set; } = string.Empty; // Name of the CORS policy to apply, if any |
| | | 30 | | /// <summary> |
| | | 31 | | /// If true, short-circuits the pipeline after this route. |
| | | 32 | | /// </summary> |
| | 43 | 33 | | public bool ShortCircuit { get; set; } // If true, short-circuit the pipeline after this route |
| | | 34 | | /// <summary> |
| | | 35 | | /// Status code to return if short-circuiting the pipeline after this route. |
| | | 36 | | /// </summary> |
| | 8 | 37 | | public int? ShortCircuitStatusCode { get; set; } = null; // Status code to return if short-circuiting |
| | | 38 | | /// <summary> |
| | | 39 | | /// If true, allows anonymous access to this route. |
| | | 40 | | /// </summary> |
| | 41 | 41 | | public bool AllowAnonymous { get; set; } |
| | | 42 | | /// <summary> |
| | | 43 | | /// If true, disables antiforgery protection for this route. |
| | | 44 | | /// </summary> |
| | 66 | 45 | | public bool DisableAntiforgery { get; set; } |
| | | 46 | | /// <summary> |
| | | 47 | | /// If true, disables response compression for this route. |
| | | 48 | | /// </summary> |
| | 40 | 49 | | public bool DisableResponseCompression { get; set; } |
| | | 50 | | /// <summary> |
| | | 51 | | /// The name of the rate limit policy to apply to this route, if any. |
| | | 52 | | /// </summary> |
| | 42 | 53 | | public string? RateLimitPolicyName { get; set; } |
| | | 54 | | /// <summary> |
| | | 55 | | /// Endpoints to bind the route to, if any. |
| | | 56 | | /// </summary> |
| | 279 | 57 | | public string[]? Endpoints { get; set; } = []; |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// Default response content type for this route. |
| | | 61 | | /// </summary> |
| | 5 | 62 | | public string? DefaultResponseContentType { get; set; } |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// OpenAPI metadata for this route. |
| | | 66 | | /// </summary> |
| | 274 | 67 | | public Dictionary<HttpVerb, OpenAPIPathMetadata> OpenAPI { get; set; } = []; // OpenAPI metadata for this route |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// Path-level OpenAPI common metadata for this route. |
| | | 71 | | /// </summary> |
| | 2 | 72 | | public OpenAPICommonMetadata? PathLevelOpenAPIMetadata { get; set; } |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// Script code and language options for this route. |
| | | 76 | | /// </summary> |
| | 542 | 77 | | public LanguageOptions ScriptCode { get; init; } = new LanguageOptions(); |
| | | 78 | | /// <summary> |
| | | 79 | | /// If true, throws an exception on duplicate routes. |
| | | 80 | | /// </summary> |
| | 12 | 81 | | public bool ThrowOnDuplicate { get; set; } |
| | | 82 | | |
| | | 83 | | /// <summary> |
| | | 84 | | /// Callback requests associated with this route. |
| | | 85 | | /// </summary> |
| | 228 | 86 | | public List<CallbackPlan> CallbackPlan { get; set; } = []; |
| | | 87 | | |
| | | 88 | | /// <summary> |
| | | 89 | | /// Returns a string representation of the MapRouteOptions. |
| | | 90 | | /// </summary> |
| | | 91 | | /// <returns></returns> |
| | | 92 | | public override string ToString() |
| | | 93 | | { |
| | 1 | 94 | | var verbs = HttpVerbs.Count > 0 ? string.Join(",", HttpVerbs) : "ANY"; |
| | 1 | 95 | | return $"{verbs} {Pattern}"; |
| | | 96 | | } |
| | | 97 | | |
| | | 98 | | /// <summary> |
| | | 99 | | /// Adds security requirement information to this route's authorization settings. |
| | | 100 | | /// </summary> |
| | | 101 | | /// <param name="schemes">the authorization schemes required for this route</param> |
| | | 102 | | /// <param name="policies">the authorization policies required for this route</param> |
| | | 103 | | public void AddSecurityRequirementObject(List<string>? schemes, List<string>? policies) |
| | | 104 | | { |
| | 0 | 105 | | if (schemes is { Count: > 0 }) |
| | | 106 | | { |
| | 0 | 107 | | RequireSchemes.AddRange(schemes); |
| | | 108 | | } |
| | | 109 | | |
| | 0 | 110 | | if (policies is { Count: > 0 }) |
| | | 111 | | { |
| | 0 | 112 | | RequirePolicies.AddRange(policies); |
| | | 113 | | } |
| | 0 | 114 | | } |
| | | 115 | | } |