// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Text;
namespace Microsoft.AspNetCore.Cors.Infrastructure
{
///
/// Results returned by .
///
public class CorsResult
{
private TimeSpan? _preflightMaxAge;
///
/// Gets or sets the allowed origin.
///
public string AllowedOrigin { get; set; }
///
/// Gets or sets a value indicating whether the resource supports user credentials.
///
public bool SupportsCredentials { get; set; }
///
/// Gets the allowed methods.
///
public IList AllowedMethods { get; } = new List();
///
/// Gets the allowed headers.
///
public IList AllowedHeaders { get; } = new List();
///
/// Gets the allowed headers that can be exposed on the response.
///
public IList AllowedExposedHeaders { get; } = new List();
///
/// Gets or sets a value indicating if a 'Vary' header with the value 'Origin' is required.
///
public bool VaryByOrigin { get; set; }
///
/// Gets or sets the for which the results of a preflight request can be cached.
///
public TimeSpan? PreflightMaxAge
{
get
{
return _preflightMaxAge;
}
set
{
if (value < TimeSpan.Zero)
{
throw new ArgumentOutOfRangeException(nameof(value), Resources.PreflightMaxAgeOutOfRange);
}
_preflightMaxAge = value;
}
}
///
/// Returns a that represents this instance.
///
///
/// A that represents this instance.
///
public override string ToString()
{
var builder = new StringBuilder();
builder.Append("AllowCredentials: ");
builder.Append(SupportsCredentials);
builder.Append(", PreflightMaxAge: ");
builder.Append(PreflightMaxAge.HasValue ?
PreflightMaxAge.Value.TotalSeconds.ToString() : "null");
builder.Append(", AllowOrigin: ");
builder.Append(AllowedOrigin);
builder.Append(", AllowExposedHeaders: {");
builder.Append(string.Join(",", AllowedExposedHeaders));
builder.Append("}");
builder.Append(", AllowHeaders: {");
builder.Append(string.Join(",", AllowedHeaders));
builder.Append("}");
builder.Append(", AllowMethods: {");
builder.Append(string.Join(",", AllowedMethods));
builder.Append("}");
return builder.ToString();
}
}
}