Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ae27d22

Browse files
committed
Use WebHeaderEncoding to encode status description text
1 parent 25d27b6 commit ae27d22

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/System.Net.HttpListener/src/System.Net.HttpListener.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@
9494
<Compile Include="$(CommonPath)\System\Net\UriScheme.cs">
9595
<Link>Common\System\Net\UriScheme.cs</Link>
9696
</Compile>
97+
<Compile Include="$(CommonPath)\System\Net\WebHeaderEncoding.cs">
98+
<Link>Common\System\Net\WebHeaderEncoding.cs</Link>
99+
</Compile>
97100
<Compile Include="$(CommonPath)\System\Net\WebSockets\WebSocketValidate.cs">
98101
<Link>Common\System\Net\WebSockets\WebSocketValidate.cs</Link>
99102
</Compile>
@@ -125,9 +128,6 @@
125128
<Compile Include="$(CommonPath)\System\Net\InternalException.cs">
126129
<Link>Common\System\Net\InternalException.cs</Link>
127130
</Compile>
128-
<Compile Include="$(CommonPath)\System\Net\WebHeaderEncoding.cs">
129-
<Link>Common\System\Net\WebHeaderEncoding.cs</Link>
130-
</Compile>
131131
<Compile Include="System\Net\Windows\HttpResponseStream.Windows.cs" />
132132
<Compile Include="System\Net\Windows\HttpResponseStreamAsyncResult.cs" />
133133
<Compile Include="System\Net\Windows\WebSockets\ServerWebSocket.cs" />

src/System.Net.HttpListener/src/System/Net/Managed/HttpListenerResponse.Managed.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,13 @@ internal void SendHeaders(bool closing, MemoryStream ms, bool isWebSocketHandsha
266266

267267
Encoding encoding = Encoding.Default;
268268
StreamWriter writer = new StreamWriter(ms, encoding, 256);
269-
writer.Write("HTTP/{0} {1} {2}\r\n", _version, _statusCode, StatusDescription);
270-
string headers_str = FormatHeaders(_webHeaders);
271-
writer.Write(headers_str);
269+
writer.Write("HTTP/{0} {1} ", _version, _statusCode);
270+
writer.Flush();
271+
byte[] statusDescriptionBytes = WebHeaderEncoding.GetBytes(StatusDescription);
272+
ms.Write(statusDescriptionBytes, 0, statusDescriptionBytes.Length);
273+
writer.Write("\r\n");
274+
275+
writer.Write(FormatHeaders(_webHeaders));
272276
writer.Flush();
273277
int preamble = encoding.GetPreamble().Length;
274278
EnsureResponseStream();

src/System.Net.HttpListener/tests/HttpListenerResponseTests.Headers.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,7 @@ public async Task StatusDescription_GetWithCustomStatusCode_ReturnsExpected(int
333333
[InlineData("A !#\t1\u1234", "A !#\t14", 125)] //
334334
[InlineData("StatusDescription", "StatusDescription", 135)]
335335
[InlineData(" StatusDescription ", " StatusDescription ", 139)]
336-
// The managed implementation should use WebHeaderEncoding to encode unicode headers.
337-
[ConditionalTheory(nameof(Helpers) + "." + nameof(Helpers.IsWindowsImplementation))] // [ActiveIssue(19976, TestPlatforms.AnyUnix)]
336+
[ConditionalTheory(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotOneCoreUAP))]
338337
public async Task StatusDescription_SetCustom_Success(string statusDescription, string expectedStatusDescription, int expectedNumberOfBytes)
339338
{
340339
using (HttpListenerResponse response = await GetResponse())

0 commit comments

Comments
 (0)