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