Skip to content

Commit

Permalink
Add option to set CORS exposed headers (#16258)
Browse files Browse the repository at this point in the history
Co-authored-by: Vaclav Sezima <[email protected]>
Co-authored-by: Mike Alhayek <[email protected]>
Co-authored-by: Hisham Bin Ateya <[email protected]>
  • Loading branch information
4 people authored Jun 7, 2024
1 parent 07a655b commit da73489
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ var corsApp = new Vue({
allowedHeaders: [],
allowAnyHeader: true,
allowCredentials: true,
isDefaultPolicy: false
isDefaultPolicy: false,
exposedHeaders: []
};
},
editPolicy: function (policy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public async Task<ActionResult> Index()
AllowAnyOrigin = policySetting.AllowAnyOrigin,
AllowedOrigins = policySetting.AllowedOrigins,
AllowCredentials = policySetting.AllowCredentials,
IsDefaultPolicy = policySetting.IsDefaultPolicy
IsDefaultPolicy = policySetting.IsDefaultPolicy,
ExposedHeaders = policySetting.ExposedHeaders,
};

list.Add(policyViewModel);
Expand Down Expand Up @@ -113,7 +114,8 @@ public async Task<ActionResult> IndexPOST()
AllowedHeaders = settingViewModel.AllowedHeaders,
AllowedMethods = settingViewModel.AllowedMethods,
AllowedOrigins = settingViewModel.AllowedOrigins,
IsDefaultPolicy = settingViewModel.IsDefaultPolicy
IsDefaultPolicy = settingViewModel.IsDefaultPolicy,
ExposedHeaders = settingViewModel.ExposedHeaders,
});

if (settingViewModel.AllowAnyOrigin && settingViewModel.AllowCredentials)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public void Configure(CorsOptions options)
{
configurePolicy.DisallowCredentials();
}
if (corsPolicy.ExposedHeaders?.Length > 0)
{
configurePolicy.WithExposedHeaders(corsPolicy.ExposedHeaders);
}
});

if (corsPolicy.IsDefaultPolicy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public class CorsPolicySetting
public bool AllowCredentials { get; set; }

public bool IsDefaultPolicy { get; set; }

public string[] ExposedHeaders { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public class CorsPolicyViewModel
public bool AllowCredentials { get; set; }

public bool IsDefaultPolicy { get; set; }

public string[] ExposedHeaders { get; set; }
}
}
12 changes: 12 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Cors/Views/Admin/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@
</div>
</div>
</div>
<div class="card mb-3">
<div class="card-body">
<h5 class="card-title">@T["Exposed headers"]
<span class="hint dashed">@T["Configure which headers should be exposed."]</span>
</h5>

<div>
<span class="hint">@T["Sets response header 'Access-Control-Expose-Headers'."]</span>
<options-list v-bind:options="policy.exposedHeaders" optionType="@T["Header"]" title="@T["Exposed headers"]" subTitle="" />
</div>
</div>
</div>
<div class="mb-3">
<button type="button" class="btn btn-primary" v-on:click="$emit('ok', policy, $event)">@T["Save"]</button>
<button type="button" class="btn btn-secondary" v-on:click="$emit('back')">@T["Cancel"]</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ var corsApp = new Vue({
allowedHeaders: [],
allowAnyHeader: true,
allowCredentials: true,
isDefaultPolicy: false
isDefaultPolicy: false,
exposedHeaders: []
};
},
editPolicy: function editPolicy(policy) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit da73489

Please sign in to comment.