Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
97d4730
Implement more ServicePoint properties
liveans Jan 26, 2024
b9fdca4
Implement more properties
liveans Jan 31, 2024
69055bb
Make implementation correct
liveans Feb 1, 2024
3591f1a
Change UseNagleAlgorithm default to false
liveans Feb 1, 2024
d861319
Update src/libraries/System.Net.Requests/src/System/Net/HttpWebReques…
liveans Feb 5, 2024
340d7e4
Merge branch 'main' into httpwebrequest-implement-more-property
liveans Feb 5, 2024
043647c
Review feedback
liveans Feb 9, 2024
f843727
Start implement DnsRoundRobin
liveans Feb 9, 2024
f296718
Merge branch 'main' into httpwebrequest-implement-more-property
liveans Feb 9, 2024
c61e5ed
remove passing parameter over ctor for static prop
liveans Feb 9, 2024
30bd75c
Change DefaultMaximumErrorResponseLength default value to -1
liveans Feb 9, 2024
cf3003d
Update ServicePoint parameter passing, implement Certificate on Servi…
liveans Feb 11, 2024
33abd52
Change servicePoint to nullable parameter again and fix bind test
liveans Feb 12, 2024
3033c4a
Change static variable test to RemoteExecutor
liveans Feb 12, 2024
2ee83de
Fix bind throw test for linux and add async to remote executor
liveans Feb 12, 2024
3be4532
Update src/libraries/System.Net.Requests/src/System/Net/HttpWebReques…
liveans Feb 15, 2024
f1ea117
Review feedback
liveans Feb 15, 2024
9260105
Merge branch 'httpwebrequest-implement-more-property' of github.com:l…
liveans Feb 15, 2024
8d28f97
Skip throw bind on Linux
liveans Feb 16, 2024
970bbb1
Add disable reuseaddr
liveans Feb 18, 2024
d9ef66d
Revert "Add disable reuseaddr"
liveans Feb 18, 2024
67655be
some changes on tests
liveans Feb 18, 2024
86f156c
Refactor GetResponseStream method to use TruncatedReadStream
liveans Feb 20, 2024
ca6b379
Fix tests
liveans Feb 20, 2024
89040f6
Convert static property test to RemoteExecutor
liveans Feb 20, 2024
66f7abd
Delete unused NameResolution project from Requests csproj
liveans Feb 20, 2024
50a0f2f
Revert "Delete unused NameResolution project from Requests csproj"
liveans Feb 20, 2024
f9cb55f
Fix socket shutdown
liveans Feb 20, 2024
8c3f0c4
simple changes on test
liveans Feb 20, 2024
a5c136a
Change sync call inside RemoteExecutor
liveans Feb 22, 2024
1d9708d
Update src/libraries/System.Net.Requests/src/System/Net/HttpWebRespon…
liveans Feb 27, 2024
ab78cd1
Merge branch 'main' into httpwebrequest-implement-more-property
liveans Feb 27, 2024
06f8d95
Apply suggestions from code review
liveans Feb 28, 2024
05af2e0
Review feedback
liveans Feb 28, 2024
47d7f27
Change exception handling on remote executor test
liveans Feb 28, 2024
7aa734f
Change connection logic
liveans Feb 28, 2024
657a334
Revert "Change exception handling on remote executor test"
liveans Feb 28, 2024
06f1324
Add forgotten disposal
liveans Feb 28, 2024
520ba04
Revert "Change connection logic"
liveans Feb 28, 2024
a9368bf
Review feedback
liveans Feb 28, 2024
f8cdea3
Apply suggestions from code review
liveans Mar 1, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Review feedback
  • Loading branch information
liveans committed Feb 28, 2024
commit 05af2e0afca8c2a223dbf1fac907f97bf323d618
3 changes: 3 additions & 0 deletions src/libraries/System.Net.Requests/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,7 @@
<data name="net_proxyschemenotsupported" xml:space="preserve">
<value>The ServicePointManager does not support proxies with the {0} scheme.</value>
</data>
<data name="net_maximumbindretries" xml:space="preserve">
<value>Reached maximum number of BindIPEndPointDelegate retries</value>
</data>
</root>
16 changes: 14 additions & 2 deletions src/libraries/System.Net.Requests/src/System/Net/HttpWebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class HttpWebRequest : WebRequest, ISerializable
private Task<HttpResponseMessage>? _sendRequestTask;

private static int _defaultMaxResponseHeadersLength = HttpHandlerDefaults.DefaultMaxResponseHeadersLength;
private static int _defaultMaximumErrorResponseLength = -1;

private int _beginGetRequestStreamCalled;
private int _beginGetResponseCalled;
Expand Down Expand Up @@ -674,11 +675,22 @@ public static int DefaultMaximumResponseHeadersLength
}
set
{
ArgumentOutOfRangeException.ThrowIfLessThan(value, 0);
_defaultMaxResponseHeadersLength = value;
}
}

public static int DefaultMaximumErrorResponseLength { get; set; } = -1;
public static int DefaultMaximumErrorResponseLength {
get
{
return _defaultMaximumErrorResponseLength;
}
set
{
ArgumentOutOfRangeException.ThrowIfLessThan(value, -1);
_defaultMaximumErrorResponseLength = value;
}
}

private static RequestCachePolicy? _defaultCachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
private static bool _isDefaultCachePolicySet;
Expand Down Expand Up @@ -1734,7 +1746,7 @@ static void BindHelper(ServicePoint servicePoint, IPAddress[] addresses, Socket

if (retryCount >= MaxRetries)
{
throw new OverflowException(); //TODO (aaksoy): Add SR for this.
throw new OverflowException(SR.net_maximumbindretries);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public static ServicePoint FindServicePoint(Uri address, IWebProxy? proxy)
IdleSince = DateTime.Now,
Expect100Continue = Expect100Continue,
UseNagleAlgorithm = UseNagleAlgorithm,
KeepAlive = KeepAlive
KeepAlive = KeepAlive,
MaxIdleTime = MaxServicePointIdleTime
};
s_servicePointTable[tableKey] = new WeakReference<ServicePoint>(sp);

Expand Down
108 changes: 58 additions & 50 deletions src/libraries/System.Net.Requests/tests/HttpWebRequestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2194,9 +2194,9 @@ await LoopbackServer.CreateClientAndServerAsync(
async (server) =>
{
await server.AcceptConnectionAsync(
async (client) =>
async connection =>
{
await client.SendResponseAsync(statusCode: HttpStatusCode.BadRequest, content: new string('a', 10));
await connection.SendResponseAsync(statusCode: HttpStatusCode.BadRequest, content: new string('a', 10));
await tcs.Task;
});
});
Expand All @@ -2215,64 +2215,72 @@ public void HttpWebRequest_SetProtocolVersion_Success()
Assert.Equal(HttpVersion.Version11, request.ServicePoint.ProtocolVersion);
}

[Fact]
public async Task SendHttpRequest_BindIPEndPoint_Success()
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void SendHttpRequest_BindIPEndPoint_Success()
{
TaskCompletionSource tcs = new TaskCompletionSource();
await LoopbackServer.CreateClientAndServerAsync(
async (uri) =>
{
HttpWebRequest request = WebRequest.CreateHttp(uri);
request.ServicePoint.BindIPEndPointDelegate = (_, _, _) => new IPEndPoint(IPAddress.Loopback, 27277);
using (var response = (HttpWebResponse)await GetResponseAsync(request))
RemoteExecutor.Invoke(async (async) =>
{
TaskCompletionSource tcs = new TaskCompletionSource();
await LoopbackServer.CreateClientAndServerAsync(
async (uri) =>
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
tcs.SetResult();
},
async (server) =>
{
await server.AcceptConnectionAsync(
async (client) =>
HttpWebRequest request = WebRequest.CreateHttp(uri);
request.ServicePoint.BindIPEndPointDelegate = (_, _, _) => new IPEndPoint(IPAddress.Loopback, 27277);
var responseTask = bool.Parse(async) ? request.GetResponseAsync() : Task.Run(() => request.GetResponse());
using (var response = (HttpWebResponse)await responseTask)
{
var ipEp = (IPEndPoint)client.Socket.RemoteEndPoint;
Assert.Equal(27277, ipEp.Port);
await client.SendResponseAsync();
await tcs.Task;
});
});
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
tcs.SetResult();
},
async (server) =>
{
await server.AcceptConnectionAsync(
async connection =>
{
var ipEp = (IPEndPoint)connection.Socket.RemoteEndPoint;
Assert.Equal(27277, ipEp.Port);
await connection.SendResponseAsync();
await tcs.Task;
});
});
}, IsAsync.ToString());
}

[Fact]
public async Task SendHttpRequest_BindIPEndPoint_Throws()
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void SendHttpRequest_BindIPEndPoint_Throws()
{
Socket socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
socket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
ValueTask<Socket>? clientSocket = null;
CancellationTokenSource cts = new CancellationTokenSource();
if (PlatformDetection.IsLinux)
RemoteExecutor.Invoke(async (async) =>
{
socket.Listen();
clientSocket = socket.AcceptAsync(cts.Token);
}
Socket socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
socket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
ValueTask<Socket>? clientSocket = null;
CancellationTokenSource cts = new CancellationTokenSource();
if (PlatformDetection.IsLinux)
{
socket.Listen();
clientSocket = socket.AcceptAsync(cts.Token);
}

try
{
// URI shouldn't matter because it should throw exception before connection open.
HttpWebRequest request = WebRequest.CreateHttp(Configuration.Http.RemoteEchoServer);
request.ServicePoint.BindIPEndPointDelegate = (_, _, _) => (IPEndPoint)socket.LocalEndPoint!;
var exception = await Assert.ThrowsAsync<WebException>(() => GetResponseAsync(request));
Assert.IsType<OverflowException>(exception.InnerException?.InnerException);
}
finally
{
if (clientSocket is not null)
try
{
await cts.CancelAsync();
// URI shouldn't matter because it should throw exception before connection open.
HttpWebRequest request = WebRequest.CreateHttp(Configuration.Http.RemoteEchoServer);
request.ServicePoint.BindIPEndPointDelegate = (_, _, _) => (IPEndPoint)socket.LocalEndPoint!;
var exception = await Assert.ThrowsAsync<WebException>(() =>
bool.Parse(async) ? request.GetResponseAsync() : Task.Run(() => request.GetResponse()));
Assert.IsType<OverflowException>(exception.InnerException?.InnerException);
}
socket.Dispose();
cts.Dispose();
}
finally
{
if (clientSocket is not null)
{
await cts.CancelAsync();
}
socket.Dispose();
cts.Dispose();
}
}, IsAsync.ToString());
}

private void RequestStreamCallback(IAsyncResult asynchronousResult)
Expand Down