33 lines
No EOL
947 B
C#
33 lines
No EOL
947 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));
|
|
}
|
|
}
|
|
|
|
record 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");
|
|
}
|
|
} |