-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from dlcs/bugfix/195/trailing_slash_non_get
Fix #195 - Encapsulate and customize the trailing slash redirection
- Loading branch information
Showing
3 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/IIIFPresentation/API/Infrastructure/Http/Redirect/TrailingSlashRedirectRule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Microsoft.AspNetCore.Rewrite; | ||
|
||
namespace API.Infrastructure.Http.Redirect; | ||
|
||
/// <summary> | ||
/// This application specific rules about redirecting trailing slashes. | ||
/// Encapsulates the built-in RedirectRule, but only allows execution | ||
/// for GET requests - it was causing issues with PUT/POST/DELETE etc. | ||
/// </summary> | ||
public class TrailingSlashRedirectRule : IRule | ||
{ | ||
// Use built-in logic, it's internal so this is the way | ||
private static readonly IRule BaseRedirectRule | ||
= new RewriteOptions().AddRedirect("(.*)/$", "$1").Rules.Single(); | ||
|
||
#region Implementation of IRule | ||
|
||
public void ApplyRule(RewriteContext context) | ||
{ | ||
// Only for GET requests | ||
if ("GET".Equals(context.HttpContext.Request.Method, StringComparison.OrdinalIgnoreCase)) | ||
BaseRedirectRule.ApplyRule(context); | ||
} | ||
|
||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters