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

Commit 8c48c01

Browse files
Cristian PopCristian Pop
authored andcommitted
AppCompat: converting two HWR properties to no-op.
1 parent 20acda7 commit 8c48c01

File tree

2 files changed

+47
-35
lines changed

2 files changed

+47
-35
lines changed

src/System.Net.Requests/src/System/Net/HttpWebRequest.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace System.Net
2222
public class HttpWebRequest : WebRequest, ISerializable
2323
{
2424
private const int DefaultContinueTimeout = 350; // Current default value from .NET Desktop.
25+
private const int DefaultReadWriteTimeout = 5 * 60 * 1000; // 5 minutes
2526

2627
private WebHeaderCollection _webHeaderCollection = new WebHeaderCollection();
2728

@@ -50,6 +51,8 @@ public class HttpWebRequest : WebRequest, ISerializable
5051
private int _maximumResponseHeadersLen = _defaultMaxResponseHeadersLength;
5152
private ServicePoint _servicePoint;
5253
private int _timeout = WebRequest.DefaultTimeoutMilliseconds;
54+
private int _readWriteTimeout = DefaultReadWriteTimeout;
55+
5356
private HttpContinueDelegate _continueDelegate;
5457

5558
// stores the user provided Host header as Uri. If the user specified a default port explicitly we'll lose
@@ -500,17 +503,7 @@ public virtual bool AllowAutoRedirect
500503
}
501504
}
502505

503-
public override string ConnectionGroupName
504-
{
505-
get
506-
{
507-
throw NotImplemented.ByDesignWithMessage(SR.net_PropertyNotImplementedException);
508-
}
509-
set
510-
{
511-
throw NotImplemented.ByDesignWithMessage(SR.net_PropertyNotImplementedException);
512-
}
513-
}
506+
public override string ConnectionGroupName { get; set; }
514507

515508
public override bool PreAuthenticate
516509
{
@@ -795,16 +788,25 @@ public Version ProtocolVersion
795788
}
796789
}
797790

798-
799791
public int ReadWriteTimeout
800792
{
801793
get
802794
{
803-
throw NotImplemented.ByDesignWithMessage(SR.net_PropertyNotImplementedException);
795+
return _readWriteTimeout;
804796
}
805797
set
806798
{
807-
throw NotImplemented.ByDesignWithMessage(SR.net_PropertyNotImplementedException);
799+
if (RequestSubmitted)
800+
{
801+
throw new InvalidOperationException(SR.net_reqsubmitted);
802+
}
803+
804+
if (value <= 0 && value != System.Threading.Timeout.Infinite)
805+
{
806+
throw new ArgumentOutOfRangeException(nameof(value), SR.net_io_timeout_use_gt_zero);
807+
}
808+
809+
_readWriteTimeout = value;
808810
}
809811
}
810812

src/System.Net.Requests/tests/HttpWebRequestTest.cs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Net.Test.Common;
1010
using System.Runtime.Serialization.Formatters.Binary;
1111
using System.Text;
12+
using System.Threading;
1213
using System.Threading.Tasks;
1314

1415
using Xunit;
@@ -485,22 +486,15 @@ public void AllowAutoRedirect_SetAndGetBoolean_ValuesMatch(Uri remoteServer)
485486
Assert.False(request.AllowAutoRedirect);
486487
}
487488

488-
[Theory, MemberData(nameof(EchoServers))]
489-
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp, "ConnectionGroupName isn't implemented in Core")]
490-
public void ConnectionGroupName_SetAndGetGroup_ValuesMatch(Uri remoteServer)
489+
[Fact]
490+
public void ConnectionGroupName_SetAndGetGroup_ValuesMatch()
491491
{
492-
HttpWebRequest request = WebRequest.CreateHttp(remoteServer);
493-
494-
if (!PlatformDetection.IsFullFramework)
495-
{
496-
Assert.Throws<NotImplementedException>(() => request.ConnectionGroupName);
497-
}
498-
else
499-
{
500-
Assert.Null(request.ConnectionGroupName);
501-
request.ConnectionGroupName = "Group";
502-
Assert.Equal("Group", request.ConnectionGroupName);
503-
}
492+
// Note: In CoreFX changing this value will not have any effect on HTTP stack's behavior.
493+
// For app-compat reasons we allow applications to alter and read the property.
494+
HttpWebRequest request = WebRequest.CreateHttp("http://test");
495+
Assert.Null(request.ConnectionGroupName);
496+
request.ConnectionGroupName = "Group";
497+
Assert.Equal("Group", request.ConnectionGroupName);
504498
}
505499

506500
[Theory, MemberData(nameof(EchoServers))]
@@ -740,13 +734,29 @@ public void ProtocolVersion_SetThenGetHttpVersions_ValuesMatch(Uri remoteServer)
740734
Assert.Equal(HttpVersion.Version11, request.ProtocolVersion);
741735
}
742736

743-
[Theory, MemberData(nameof(EchoServers))]
744-
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Implemented in .NET Framework")]
745-
public void ReadWriteTimeout_SetThenGet_ThrowsNotImplementedException(Uri remoteServer)
737+
[Fact]
738+
public void ReadWriteTimeout_SetThenGet_ValuesMatch()
746739
{
747-
HttpWebRequest request = WebRequest.CreateHttp(remoteServer);
748-
Assert.Throws<NotImplementedException>(() => request.ReadWriteTimeout = 5);
749-
Assert.Throws<NotImplementedException>(() => request.ReadWriteTimeout);
740+
// Note: In CoreFX changing this value will not have any effect on HTTP stack's behavior.
741+
// For app-compat reasons we allow applications to alter and read the property.
742+
HttpWebRequest request = WebRequest.CreateHttp("http://test");
743+
request.ReadWriteTimeout = 5;
744+
Assert.Equal(5, request.ReadWriteTimeout);
745+
}
746+
747+
[Fact]
748+
public void ReadWriteTimeout_InfiniteValue_Ok()
749+
{
750+
HttpWebRequest request = WebRequest.CreateHttp("http://test");
751+
request.ReadWriteTimeout = Timeout.Infinite;
752+
}
753+
754+
[Fact]
755+
public void ReadWriteTimeout_NegativeOrZeroValue_Fail()
756+
{
757+
HttpWebRequest request = WebRequest.CreateHttp("http://test");
758+
Assert.Throws<ArgumentOutOfRangeException>(() => { request.ReadWriteTimeout = 0; });
759+
Assert.Throws<ArgumentOutOfRangeException>(() => { request.ReadWriteTimeout = -10; });
750760
}
751761

752762
[Theory, MemberData(nameof(EchoServers))]

0 commit comments

Comments
 (0)