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

Commit 900f9aa

Browse files
committed
Expose SocketsHttpHandler.MaxResponseDrainSize
1 parent 99c083a commit 900f9aa

File tree

4 files changed

+16
-31
lines changed

4 files changed

+16
-31
lines changed

src/System.Net.Http/ref/System.Net.Http.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ public SocketsHttpHandler() { }
248248
public System.TimeSpan Expect100ContinueTimeout { get; set; }
249249
public int MaxAutomaticRedirections { get { throw null; } set { } }
250250
public int MaxConnectionsPerServer { get { throw null; } set { } }
251+
public int MaxResponseDrainSize { get { throw null; } set { } }
251252
public int MaxResponseHeadersLength { get { throw null; } set { } }
252253
public bool PreAuthenticate { get { throw null; } set { } }
253254
public System.TimeSpan PooledConnectionIdleTimeout { get { throw null; } set { } }

src/System.Net.Http/src/ILLinkTrim.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
<assembly fullname="System.Net.Http">
33
<!-- Anonymous types are used with DiagnosticSource logging and subscribers reflect over those, calling their public getters. -->
44
<type fullname="*f__AnonymousType*" />
5-
<type fullname="System.Net.Http.SocketsHttpHandler" /> <!-- TODO #27329: Remove this once MaxResponseDrainSize is exposed -->
65
</assembly>
76
</linker>

src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public int MaxConnectionsPerServer
152152
}
153153
}
154154

155-
internal int MaxResponseDrainSize // TODO #27329: Expose publicly.
155+
public int MaxResponseDrainSize
156156
{
157157
get => _settings._maxResponseDrainSize;
158158
set

src/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,33 +77,18 @@ public sealed class SocketsHttpHandler_HttpClientHandler_ResponseDrain_Test : Ht
7777
{
7878
protected override bool UseSocketsHttpHandler => true;
7979

80-
// Set MaxResponseDrainSize. TODO #27329: Avoid reflection once exposed publicly.
81-
private int GetMaxResponseDrainSize(SocketsHttpHandler handler) =>
82-
(int)typeof(SocketsHttpHandler).GetProperty("MaxResponseDrainSize", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(handler);
83-
private void SetMaxResponseDrainSize(SocketsHttpHandler handler, int value)
84-
{
85-
try
86-
{
87-
typeof(SocketsHttpHandler).GetProperty("MaxResponseDrainSize", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(handler, value);
88-
}
89-
catch (TargetInvocationException tie)
90-
{
91-
throw tie.InnerException;
92-
}
93-
}
94-
9580
[Fact]
9681
public void MaxResponseDrainSize_Roundtrips()
9782
{
9883
using (var handler = new SocketsHttpHandler())
9984
{
100-
Assert.Equal(1024 * 1024, GetMaxResponseDrainSize(handler));
85+
Assert.Equal(1024 * 1024, handler.MaxResponseDrainSize);
10186

102-
SetMaxResponseDrainSize(handler, 0);
103-
Assert.Equal(0, GetMaxResponseDrainSize(handler));
87+
handler.MaxResponseDrainSize = 0;
88+
Assert.Equal(0, handler.MaxResponseDrainSize);
10489

105-
SetMaxResponseDrainSize(handler, int.MaxValue);
106-
Assert.Equal(int.MaxValue, GetMaxResponseDrainSize(handler));
90+
handler.MaxResponseDrainSize = int.MaxValue;
91+
Assert.Equal(int.MaxValue, handler.MaxResponseDrainSize);
10792
}
10893
}
10994

@@ -112,12 +97,12 @@ public void MaxResponseDrainSize_InvalidArgument_Throws()
11297
{
11398
using (var handler = new SocketsHttpHandler())
11499
{
115-
Assert.Equal(1024 * 1024, GetMaxResponseDrainSize(handler));
100+
Assert.Equal(1024 * 1024, handler.MaxResponseDrainSize);
116101

117-
AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => SetMaxResponseDrainSize(handler, -1));
118-
AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => SetMaxResponseDrainSize(handler, int.MinValue));
102+
AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => handler.MaxResponseDrainSize = -1);
103+
AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => handler.MaxResponseDrainSize = int.MinValue);
119104

120-
Assert.Equal(1024 * 1024, GetMaxResponseDrainSize(handler));
105+
Assert.Equal(1024 * 1024, handler.MaxResponseDrainSize);
121106
}
122107
}
123108

@@ -127,10 +112,10 @@ public void MaxResponseDrainSize_SetAfterUse_Throws()
127112
using (var handler = new SocketsHttpHandler())
128113
using (var client = new HttpClient(handler))
129114
{
130-
SetMaxResponseDrainSize(handler, 1);
115+
handler.MaxResponseDrainSize = 1;
131116
client.GetAsync("http://" + Guid.NewGuid().ToString("N")); // ignoring failure
132-
Assert.Equal(1, GetMaxResponseDrainSize(handler));
133-
Assert.Throws<InvalidOperationException>(() => SetMaxResponseDrainSize(handler, 1));
117+
Assert.Equal(1, handler.MaxResponseDrainSize);
118+
Assert.Throws<InvalidOperationException>(() => handler.MaxResponseDrainSize = 1);
134119
}
135120
}
136121

@@ -145,7 +130,7 @@ await LoopbackServer.CreateClientAndServerAsync(
145130
async url =>
146131
{
147132
var handler = new SocketsHttpHandler();
148-
SetMaxResponseDrainSize(handler, maxDrainSize);
133+
handler.MaxResponseDrainSize = maxDrainSize;
149134

150135
// Set MaxConnectionsPerServer to 1. This will ensure we will wait for the previous request to drain (or fail to)
151136
handler.MaxConnectionsPerServer = 1;
@@ -190,7 +175,7 @@ await LoopbackServer.CreateClientAndServerAsync(
190175
async url =>
191176
{
192177
var handler = new SocketsHttpHandler();
193-
SetMaxResponseDrainSize(handler, maxDrainSize);
178+
handler.MaxResponseDrainSize = maxDrainSize;
194179

195180
// Set MaxConnectionsPerServer to 1. This will ensure we will wait for the previous request to drain (or fail to)
196181
handler.MaxConnectionsPerServer = 1;

0 commit comments

Comments
 (0)