Use HeaderUtilities.FormatDate in DateHeaderValueManager (#1132)
This commit is contained in:
parent
2c94884da9
commit
03f8a7a217
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||
{
|
||||
|
|
@ -170,8 +171,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
|||
/// <param name="value">A DateTimeOffset value</param>
|
||||
private void SetDateValues(DateTimeOffset value)
|
||||
{
|
||||
// See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 for required format of Date header
|
||||
var dateValue = value.ToString(Constants.RFC1123DateFormat);
|
||||
var dateValue = HeaderUtilities.FormatDate(value);
|
||||
var dateBytes = new byte[_datePreambleBytes.Length + dateValue.Length];
|
||||
Buffer.BlockCopy(_datePreambleBytes, 0, dateBytes, 0, _datePreambleBytes.Length);
|
||||
Encoding.ASCII.GetBytes(dateValue, 0, dateValue.Length, dateBytes, _datePreambleBytes.Length);
|
||||
|
|
|
|||
|
|
@ -17,12 +17,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
|
|||
/// </summary>
|
||||
public const string UnixPipeHostPrefix = "unix:/";
|
||||
|
||||
/// <summary>
|
||||
/// DateTime format string for RFC1123. See https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#RFC1123
|
||||
/// for info on the format.
|
||||
/// </summary>
|
||||
public const string RFC1123DateFormat = "r";
|
||||
|
||||
public const string ServerName = "Kestrel";
|
||||
|
||||
private static int? GetEADDRINUSE()
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -12,6 +11,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
|||
{
|
||||
public class DateHeaderValueManagerTests
|
||||
{
|
||||
/// <summary>
|
||||
/// DateTime format string for RFC1123.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#RFC1123 for info on the format.
|
||||
/// </remarks>
|
||||
private const string Rfc1123DateFormat = "r";
|
||||
|
||||
[Fact]
|
||||
public void GetDateHeaderValue_ReturnsDateValueInRFC1123Format()
|
||||
{
|
||||
|
|
@ -34,7 +41,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
|||
dateHeaderValueManager.Dispose();
|
||||
}
|
||||
|
||||
Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result);
|
||||
Assert.Equal(now.ToString(Rfc1123DateFormat), result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -63,8 +70,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
|||
dateHeaderValueManager.Dispose();
|
||||
}
|
||||
|
||||
Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result1);
|
||||
Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result2);
|
||||
Assert.Equal(now.ToString(Rfc1123DateFormat), result1);
|
||||
Assert.Equal(now.ToString(Rfc1123DateFormat), result2);
|
||||
Assert.Equal(1, systemClock.UtcNowCalled);
|
||||
}
|
||||
|
||||
|
|
@ -96,8 +103,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
|||
dateHeaderValueManager.Dispose();
|
||||
}
|
||||
|
||||
Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result1);
|
||||
Assert.Equal(future.ToString(Constants.RFC1123DateFormat), result2);
|
||||
Assert.Equal(now.ToString(Rfc1123DateFormat), result1);
|
||||
Assert.Equal(future.ToString(Rfc1123DateFormat), result2);
|
||||
Assert.True(systemClock.UtcNowCalled >= 2);
|
||||
}
|
||||
|
||||
|
|
@ -119,8 +126,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
|||
systemClock.UtcNow = future;
|
||||
var result2 = dateHeaderValueManager.GetDateHeaderValues().String;
|
||||
|
||||
Assert.Equal(now.ToString(Constants.RFC1123DateFormat), result1);
|
||||
Assert.Equal(future.ToString(Constants.RFC1123DateFormat), result2);
|
||||
Assert.Equal(now.ToString(Rfc1123DateFormat), result1);
|
||||
Assert.Equal(future.ToString(Rfc1123DateFormat), result2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue