This commit is contained in:
Mikael Mengistu 2016-10-06 16:23:55 -07:00 коммит произвёл GitHub
Родитель cd833a7d63
Коммит 9814f3bfbc
5 изменённых файлов: 15 добавлений и 12 удалений

Просмотреть файл

@ -1,13 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
{
public enum RedirectType
{
Permanent = 301,
Found = 302,
SeeOther = 303,
Temporary = 307
Permanent = StatusCodes.Status301MovedPermanently,
Found = StatusCodes.Status302Found,
SeeOther = StatusCodes.Status303SeeOther,
Temporary = StatusCodes.Status307TemporaryRedirect
}
}

Просмотреть файл

@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlActions
QueryString.FromUriComponent(
pattern.Substring(split)));
// not using the response.redirect here because status codes may be 301, 302, 307, 308
// not using the response.redirect here because status codes may be 301, 302, 307, 308
response.Headers[HeaderNames.Location] = pathBase + pattern.Substring(0, split) + query;
}
else

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Rewrite.Internal;
namespace Microsoft.AspNetCore.Rewrite
@ -58,7 +59,7 @@ namespace Microsoft.AspNetCore.Rewrite
/// <returns>The Rewrite options.</returns>
public static RewriteOptions AddRedirect(this RewriteOptions options, string regex, string replacement)
{
return AddRedirect(options, regex, replacement, statusCode: 302);
return AddRedirect(options, regex, replacement, statusCode: StatusCodes.Status302Found);
}
/// <summary>
@ -83,7 +84,7 @@ namespace Microsoft.AspNetCore.Rewrite
/// <returns></returns>
public static RewriteOptions AddRedirectToHttpsPermanent(this RewriteOptions options)
{
return AddRedirectToHttps(options, statusCode: 301, sslPort: null);
return AddRedirectToHttps(options, statusCode: StatusCodes.Status301MovedPermanently, sslPort: null);
}
/// <summary>
@ -92,7 +93,7 @@ namespace Microsoft.AspNetCore.Rewrite
/// <param name="options">The <see cref="RewriteOptions"/>.</param>
public static RewriteOptions AddRedirectToHttps(this RewriteOptions options)
{
return AddRedirectToHttps(options, statusCode: 302, sslPort: null);
return AddRedirectToHttps(options, statusCode: StatusCodes.Status302Found, sslPort: null);
}
/// <summary>

Просмотреть файл

@ -247,7 +247,7 @@ namespace Microsoft.AspNetCore.Rewrite.Tests.ModRewrite
var response = await server.CreateClient().GetAsync(input);
Assert.Equal(response.StatusCode, (HttpStatusCode)301);
Assert.Equal(response.Headers.Location.AbsoluteUri, @"https://www.example.com/foo/");
Assert.Equal(@"https://www.example.com/foo/", response.Headers.Location.AbsoluteUri);
}
[Theory]

Просмотреть файл

@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Rewrite.Tests.CodeRules
[Fact]
public async Task CheckRedirectPath()
{
var options = new RewriteOptions().AddRedirect("(.*)","http://example.com/$1", statusCode: 301);
var options = new RewriteOptions().AddRedirect("(.*)","http://example.com/$1", statusCode: StatusCodes.Status301MovedPermanently);
var builder = new WebHostBuilder()
.Configure(app =>
{
@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Rewrite.Tests.CodeRules
[Fact]
public async Task CheckRedirectToHttps()
{
var options = new RewriteOptions().AddRedirectToHttps(statusCode: 301);
var options = new RewriteOptions().AddRedirectToHttps(statusCode: StatusCodes.Status301MovedPermanently);
var builder = new WebHostBuilder()
.Configure(app =>
{
@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Rewrite.Tests.CodeRules
[Fact]
public async Task CheckIfEmptyStringRedirectCorrectly()
{
var options = new RewriteOptions().AddRedirect("(.*)", "$1", statusCode: 301);
var options = new RewriteOptions().AddRedirect("(.*)", "$1", statusCode: StatusCodes.Status301MovedPermanently);
var builder = new WebHostBuilder()
.Configure(app =>
{