@@ -24,18 +24,21 @@ public static class CorsHttpConfigurationExtensions
2424 /// Enables the support for CORS.
2525 /// </summary>
2626 /// <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 )
2829 {
29- EnableCors ( httpConfiguration , null ) ;
30+ EnableCors ( httpConfiguration , null , rethrowExceptions ) ;
3031 }
3132
3233 /// <summary>
3334 /// Enables the support for CORS.
3435 /// </summary>
3536 /// <param name="httpConfiguration">The <see cref="HttpConfiguration"/>.</param>
3637 /// <param name="defaultPolicyProvider">The default <see cref="ICorsPolicyProvider"/>.</param>
38+ /// <param name="rethrowExceptions">Indicates whether upstream exceptions should be rethrown</param>
3739 /// <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 )
3942 {
4043 if ( httpConfiguration == null )
4144 {
@@ -49,11 +52,11 @@ public static void EnableCors(this HttpConfiguration httpConfiguration, ICorsPol
4952 httpConfiguration . SetCorsPolicyProviderFactory ( policyProviderFactory ) ;
5053 }
5154
52- AddCorsMessageHandler ( httpConfiguration ) ;
55+ AddCorsMessageHandler ( httpConfiguration , rethrowExceptions ) ;
5356 }
5457
5558 [ 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 )
5760 {
5861 object corsEnabled ;
5962 if ( ! httpConfiguration . Properties . TryGetValue ( CorsEnabledKey , out corsEnabled ) )
@@ -64,7 +67,7 @@ private static void AddCorsMessageHandler(this HttpConfiguration httpConfigurati
6467 if ( ! config . Properties . TryGetValue ( CorsEnabledKey , out corsEnabled ) )
6568 {
6669 // 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 ) ) ;
6871
6972 ITraceWriter traceWriter = config . Services . GetTraceWriter ( ) ;
7073
0 commit comments