Make sure to add whitespace after the status code even if the reasonphrase is empty (#2184)
This commit is contained in:
parent
98de3aa50d
commit
5e9e3a8574
|
|
@ -222,9 +222,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
|
|
||||||
default:
|
default:
|
||||||
var predefinedReasonPhrase = WebUtilities.ReasonPhrases.GetReasonPhrase(statusCode);
|
var predefinedReasonPhrase = WebUtilities.ReasonPhrases.GetReasonPhrase(statusCode);
|
||||||
|
// https://tools.ietf.org/html/rfc7230#section-3.1.2 requires trailing whitespace regardless of reason phrase
|
||||||
|
var formattedStatusCode = statusCode.ToString(CultureInfo.InvariantCulture) + " ";
|
||||||
return string.IsNullOrEmpty(predefinedReasonPhrase)
|
return string.IsNullOrEmpty(predefinedReasonPhrase)
|
||||||
? Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture))
|
? Encoding.ASCII.GetBytes(formattedStatusCode)
|
||||||
: Encoding.ASCII.GetBytes(statusCode.ToString(CultureInfo.InvariantCulture) + " " + predefinedReasonPhrase);
|
: Encoding.ASCII.GetBytes(formattedStatusCode + predefinedReasonPhrase);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
// 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 Xunit;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
||||||
|
{
|
||||||
|
public class ReasonPhraseTests
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData(999, "Unknown", "999 Unknown")]
|
||||||
|
[InlineData(999, null, "999 ")]
|
||||||
|
[InlineData(StatusCodes.Status200OK, "OK", "200 OK")]
|
||||||
|
[InlineData(StatusCodes.Status200OK, null, "200 OK")]
|
||||||
|
public void Formatting(int statusCode, string reasonPhrase, string expectedResult)
|
||||||
|
{
|
||||||
|
var bytes = Internal.Http.ReasonPhrases.ToStatusBytes(statusCode, reasonPhrase);
|
||||||
|
Assert.NotNull(bytes);
|
||||||
|
Assert.Equal(expectedResult, Encoding.ASCII.GetString(bytes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue