Skip to content

Commit a317419

Browse files
authored
Avoid ASCII processing during HostFilteringMiddleware static initialization (#52978)
1 parent 4eafb8e commit a317419

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/Middleware/HostFiltering/src/HostFilteringMiddleware.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Runtime.CompilerServices;
5-
using System.Text;
65
using Microsoft.AspNetCore.Http;
76
using Microsoft.Extensions.Logging;
87
using Microsoft.Extensions.Options;
@@ -16,14 +15,14 @@ namespace Microsoft.AspNetCore.HostFiltering;
1615
public class HostFilteringMiddleware
1716
{
1817
// Matches Http.Sys.
19-
private static readonly byte[] DefaultResponse = Encoding.ASCII.GetBytes(
20-
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\"http://www.w3.org/TR/html4/strict.dtd\">\r\n"
21-
+ "<HTML><HEAD><TITLE>Bad Request</TITLE>\r\n"
22-
+ "<META HTTP-EQUIV=\"Content-Type\" Content=\"text/html; charset=us-ascii\"></ HEAD >\r\n"
23-
+ "<BODY><h2>Bad Request - Invalid Hostname</h2>\r\n"
24-
+ "<hr><p>HTTP Error 400. The request hostname is invalid.</p>\r\n"
25-
+ "</BODY></HTML>"
26-
);
18+
private static readonly byte[] DefaultResponse = (
19+
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\"http://www.w3.org/TR/html4/strict.dtd\">\r\n"u8
20+
+ "<HTML><HEAD><TITLE>Bad Request</TITLE>\r\n"u8
21+
+ "<META HTTP-EQUIV=\"Content-Type\" Content=\"text/html; charset=us-ascii\"></ HEAD >\r\n"u8
22+
+ "<BODY><h2>Bad Request - Invalid Hostname</h2>\r\n"u8
23+
+ "<hr><p>HTTP Error 400. The request hostname is invalid.</p>\r\n"u8
24+
+ "</BODY></HTML>"u8
25+
).ToArray();
2726

2827
private readonly RequestDelegate _next;
2928
private readonly ILogger<HostFilteringMiddleware> _logger;

0 commit comments

Comments
 (0)