@@ -24,18 +24,21 @@ public static class CorsHttpConfigurationExtensions
24
24
/// Enables the support for CORS.
25
25
/// </summary>
26
26
/// <param name="httpConfiguration">The <see cref="HttpConfiguration"/>.</param>
27
- public static void EnableCors ( this HttpConfiguration httpConfiguration )
27
+ /// <param name="rethrowExceptions">Indicates whether upstream exceptions should be rethrown</param>
28
+ public static void EnableCors ( this HttpConfiguration httpConfiguration , bool rethrowExceptions = false )
28
29
{
29
- EnableCors ( httpConfiguration , null ) ;
30
+ EnableCors ( httpConfiguration , null , rethrowExceptions ) ;
30
31
}
31
32
32
33
/// <summary>
33
34
/// Enables the support for CORS.
34
35
/// </summary>
35
36
/// <param name="httpConfiguration">The <see cref="HttpConfiguration"/>.</param>
36
37
/// <param name="defaultPolicyProvider">The default <see cref="ICorsPolicyProvider"/>.</param>
38
+ /// <param name="rethrowExceptions">Indicates whether upstream exceptions should be rethrown</param>
37
39
/// <exception cref="System.ArgumentNullException">httpConfiguration</exception>
38
- public static void EnableCors ( this HttpConfiguration httpConfiguration , ICorsPolicyProvider defaultPolicyProvider )
40
+ public static void EnableCors ( this HttpConfiguration httpConfiguration , ICorsPolicyProvider defaultPolicyProvider ,
41
+ bool rethrowExceptions = false )
39
42
{
40
43
if ( httpConfiguration == null )
41
44
{
@@ -49,11 +52,11 @@ public static void EnableCors(this HttpConfiguration httpConfiguration, ICorsPol
49
52
httpConfiguration . SetCorsPolicyProviderFactory ( policyProviderFactory ) ;
50
53
}
51
54
52
- AddCorsMessageHandler ( httpConfiguration ) ;
55
+ AddCorsMessageHandler ( httpConfiguration , rethrowExceptions ) ;
53
56
}
54
57
55
58
[ SuppressMessage ( "Microsoft.Reliability" , "CA2000:Dispose objects before losing scope" , Justification = "Caller owns the disposable object" ) ]
56
- private static void AddCorsMessageHandler ( this HttpConfiguration httpConfiguration )
59
+ private static void AddCorsMessageHandler ( this HttpConfiguration httpConfiguration , bool rethrowExceptions )
57
60
{
58
61
object corsEnabled ;
59
62
if ( ! httpConfiguration . Properties . TryGetValue ( CorsEnabledKey , out corsEnabled ) )
@@ -64,7 +67,7 @@ private static void AddCorsMessageHandler(this HttpConfiguration httpConfigurati
64
67
if ( ! config . Properties . TryGetValue ( CorsEnabledKey , out corsEnabled ) )
65
68
{
66
69
// Execute this in the Initializer to ensure that the CorsMessageHandler is added last.
67
- config . MessageHandlers . Add ( new CorsMessageHandler ( config ) ) ;
70
+ config . MessageHandlers . Add ( new CorsMessageHandler ( config , rethrowExceptions ) ) ;
68
71
69
72
ITraceWriter traceWriter = config . Services . GetTraceWriter ( ) ;
70
73
0 commit comments