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

Commit e3aa9ab

Browse files
committed
Fix managed implementation handling of ContentType
Move the Windows implementation to be shared and remove the managed-specific implementation.
1 parent 56ac38a commit e3aa9ab

File tree

4 files changed

+18
-37
lines changed

4 files changed

+18
-37
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ public WebHeaderCollection Headers
2727

2828
public Encoding ContentEncoding { get; set; }
2929

30+
public string ContentType
31+
{
32+
get => Headers[HttpKnownHeaderNames.ContentType];
33+
set
34+
{
35+
CheckDisposed();
36+
if (string.IsNullOrEmpty(value))
37+
{
38+
Headers.Remove(HttpKnownHeaderNames.ContentType);
39+
}
40+
else
41+
{
42+
Headers.Set(HttpKnownHeaderNames.ContentType, value);
43+
}
44+
}
45+
}
46+
3047
public CookieCollection Cookies
3148
{
3249
get => _cookies ?? (_cookies = new CookieCollection());

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public sealed partial class HttpListenerResponse : IDisposable
3939
{
4040
private long _contentLength;
4141
private bool _clSet;
42-
private string _contentType;
4342
private bool _keepAlive = true;
4443
private HttpResponseStream _outputStream;
4544
private Version _version = HttpVersion.Version11;
@@ -74,18 +73,6 @@ public long ContentLength64
7473
}
7574
}
7675

77-
public string ContentType
78-
{
79-
get => _contentType;
80-
set
81-
{
82-
CheckDisposed();
83-
CheckSentHeaders();
84-
85-
_contentType = value;
86-
}
87-
}
88-
8976
public bool KeepAlive
9077
{
9178
get => _keepAlive;
@@ -247,11 +234,6 @@ internal void SendHeaders(bool closing, MemoryStream ms, bool isWebSocketHandsha
247234
{
248235
if (!isWebSocketHandshake)
249236
{
250-
if (_contentType != null)
251-
{
252-
_webHeaders.Set(HttpKnownHeaderNames.ContentType, _contentType);
253-
}
254-
255237
if (_webHeaders[HttpKnownHeaderNames.Server] == null)
256238
_webHeaders.Set(HttpKnownHeaderNames.Server, HttpHeaderStrings.NetCoreServerName);
257239
CultureInfo inv = CultureInfo.InvariantCulture;

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,6 @@ internal HttpListenerResponse(HttpListenerContext httpContext) : this()
5656

5757
private HttpListenerRequest HttpListenerRequest => HttpListenerContext.Request;
5858

59-
public string ContentType
60-
{
61-
get => Headers[HttpKnownHeaderNames.ContentType];
62-
set
63-
{
64-
CheckDisposed();
65-
if (string.IsNullOrEmpty(value))
66-
{
67-
Headers.Remove(HttpKnownHeaderNames.ContentType);
68-
}
69-
else
70-
{
71-
Headers.Set(HttpKnownHeaderNames.ContentType, value);
72-
}
73-
}
74-
}
75-
7659
public Stream OutputStream
7760
{
7861
get

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ public async Task ContentType_SetDisposed_ThrowsObjectDisposedException()
110110
Assert.Null(response.ContentType);
111111
}
112112

113-
// The managed implementation should not throw setting ContentType after the headers are sent.
114-
[ConditionalFact(nameof(Helpers) + "." + nameof(Helpers.IsWindowsImplementation))] // [ActiveIssue(19971, TestPlatforms.AnyUnix)]
113+
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotOneCoreUAP))]
115114
public async Task ContentType_SetAfterHeadersSent_DoesNothing()
116115
{
117116
using (HttpListenerResponse response = await GetResponse())

0 commit comments

Comments
 (0)