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