33 lines
946 B
C#
33 lines
946 B
C#
|
namespace Uwaa.HTTP.Routing;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Handles CORS preflight requests.
|
|||
|
/// </summary>
|
|||
|
public class CORS : RouterBase
|
|||
|
{
|
|||
|
public override HttpMethod Method => HttpMethod.OPTIONS;
|
|||
|
|
|||
|
public override int Arguments => 0;
|
|||
|
|
|||
|
protected override Task<HttpResponse?> GetResponseInner(HttpRequest req, HttpClientInfo info, ArraySegment<string> path)
|
|||
|
{
|
|||
|
return Task.FromResult<HttpResponse?>(new HttpResponse(200, "OK", PreflightResponseFields.Singleton));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
class PreflightResponseFields : HttpFields
|
|||
|
{
|
|||
|
public static readonly PreflightResponseFields Singleton = new PreflightResponseFields();
|
|||
|
|
|||
|
PreflightResponseFields()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
public override void EmitAll(FieldCallback callback)
|
|||
|
{
|
|||
|
base.EmitAll(callback);
|
|||
|
callback("Access-Control-Allow-Origin", "*");
|
|||
|
callback("Methods", "GET,HEAD,POST,PUT,DELETE,CONNECT,OPTIONS,TRACE,PATCH");
|
|||
|
callback("Vary", "Origin");
|
|||
|
}
|
|||
|
}
|