mirror of https://github.com/Squidex/squidex.git
3 changed files with 0 additions and 62 deletions
@ -1,52 +0,0 @@ |
|||
// ==========================================================================
|
|||
// SingleUrlsMiddleware.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace Squidex.Pipeline |
|||
{ |
|||
public sealed class SingleUrlsMiddleware |
|||
{ |
|||
private readonly RequestDelegate next; |
|||
private readonly ILogger<SingleUrlsMiddleware> logger; |
|||
|
|||
public SingleUrlsMiddleware(RequestDelegate next, ILoggerFactory factory) |
|||
{ |
|||
this.next = next; |
|||
|
|||
logger = factory.CreateLogger<SingleUrlsMiddleware>(); |
|||
} |
|||
|
|||
public async Task Invoke(HttpContext context) |
|||
{ |
|||
var currentUrl = string.Concat(context.Request.Scheme, "://", context.Request.Host, context.Request.Path); |
|||
|
|||
var hostName = context.Request.Host.ToString().ToLowerInvariant(); |
|||
if (hostName.StartsWith("www.")) |
|||
{ |
|||
hostName = hostName.Substring(4); |
|||
} |
|||
|
|||
var newUrl = string.Concat("https://", hostName, context.Request.Path); |
|||
|
|||
if (!string.Equals(newUrl, currentUrl, StringComparison.OrdinalIgnoreCase)) |
|||
{ |
|||
logger.LogError("Invalid url: {0} instead {1}", currentUrl, newUrl); |
|||
|
|||
context.Response.Redirect(newUrl + context.Request.QueryString, true); |
|||
} |
|||
else |
|||
{ |
|||
await next(context); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,5 +0,0 @@ |
|||
{ |
|||
"urls": { |
|||
"baseUrl": "https://squidex.io" |
|||
} |
|||
} |
|||
Loading…
Reference in new issue