// 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.Collections.Generic;
using System.ComponentModel;
using System.Net.Http;
using System.Web.Cors;
namespace System.Web.Http.Cors
{
///
/// CORS-related extension methods for .
///
[EditorBrowsable(EditorBrowsableState.Never)]
public static class CorsHttpResponseMessageExtensions
{
///
/// Writes the CORS headers on the response.
///
/// The .
/// The .
///
/// response
/// or
/// corsResult
///
public static void WriteCorsHeaders(this HttpResponseMessage response, CorsResult corsResult)
{
if (response == null)
{
throw new ArgumentNullException("response");
}
if (corsResult == null)
{
throw new ArgumentNullException("corsResult");
}
IDictionary corsHeaders = corsResult.ToResponseHeaders();
if (corsHeaders != null)
{
foreach (KeyValuePair header in corsHeaders)
{
response.Headers.TryAddWithoutValidation(header.Key, header.Value);
}
}
}
}
}