namespace Uwaa.HTTP.Routing;
///
/// Handles CORS preflight requests.
///
public class CORS : RouterBase
{
public override HttpMethod Method => HttpMethod.OPTIONS;
public override int Arguments => 0;
protected override Task GetResponseInner(HttpRequest req, HttpClientInfo info, ArraySegment path)
{
return Task.FromResult(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");
}
}