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

Commit ca38da9

Browse files
committed
Match desktop behavior GetRequestStream/BeginGetRequestStream throws on invalid verb
1 parent 84d5d7e commit ca38da9

File tree

2 files changed

+8
-33
lines changed

2 files changed

+8
-33
lines changed

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

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,11 +1023,6 @@ private Task<Stream> InternalGetRequestStream()
10231023
{
10241024
CheckAbort();
10251025

1026-
if (RequestSubmitted)
1027-
{
1028-
throw new InvalidOperationException(SR.net_reqsubmitted);
1029-
}
1030-
10311026
// Match Desktop behavior: prevent someone from getting a request stream
10321027
// if the protocol verb/method doesn't support it. Note that this is not
10331028
// entirely compliant RFC2616 for the aforementioned compatibility reasons.
@@ -1038,6 +1033,11 @@ private Task<Stream> InternalGetRequestStream()
10381033
throw new ProtocolViolationException(SR.net_nouploadonget);
10391034
}
10401035

1036+
if (RequestSubmitted)
1037+
{
1038+
throw new InvalidOperationException(SR.net_reqsubmitted);
1039+
}
1040+
10411041
_requestStream = new RequestStream();
10421042

10431043
return Task.FromResult((Stream)_requestStream);
@@ -1065,7 +1065,7 @@ public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, Objec
10651065
}
10661066

10671067
_requestStreamCallback = callback;
1068-
_requestStreamOperation = GetRequestStreamTask().ToApm(callback, state);
1068+
_requestStreamOperation = InternalGetRequestStream().ToApm(callback, state);
10691069

10701070
return _requestStreamOperation.Task;
10711071
}
@@ -1097,30 +1097,6 @@ public override Stream EndGetRequestStream(IAsyncResult asyncResult)
10971097
return stream;
10981098
}
10991099

1100-
private Task<Stream> GetRequestStreamTask()
1101-
{
1102-
CheckAbort();
1103-
1104-
if (RequestSubmitted)
1105-
{
1106-
throw new InvalidOperationException(SR.net_reqsubmitted);
1107-
}
1108-
1109-
// Match Desktop behavior: prevent someone from getting a request stream
1110-
// if the protocol verb/method doesn't support it. Note that this is not
1111-
// entirely compliant RFC2616 for the aforementioned compatibility reasons.
1112-
if (string.Equals(HttpMethod.Get.Method, _originVerb, StringComparison.OrdinalIgnoreCase) ||
1113-
string.Equals(HttpMethod.Head.Method, _originVerb, StringComparison.OrdinalIgnoreCase) ||
1114-
string.Equals("CONNECT", _originVerb, StringComparison.OrdinalIgnoreCase))
1115-
{
1116-
throw new ProtocolViolationException(SR.net_nouploadonget);
1117-
}
1118-
1119-
_requestStream = new RequestStream();
1120-
1121-
return Task.FromResult((Stream)_requestStream);
1122-
}
1123-
11241100
private async Task<WebResponse> SendRequest()
11251101
{
11261102
if (RequestSubmitted)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,13 +861,12 @@ public void BeginGetRequestStream_CreatePostRequestThenCallTwice_ThrowsInvalidOp
861861
}
862862

863863
[Theory, MemberData(nameof(EchoServers))]
864-
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "request stream not allowed for GET on netfx")]
865-
public void BeginGetRequestStream_CreateRequestThenBeginGetResponsePrior_ThrowsInvalidOperationException(Uri remoteServer)
864+
public void BeginGetRequestStream_CreateRequestThenBeginGetResponsePrior_ThrowsProtocolViolationException(Uri remoteServer)
866865
{
867866
HttpWebRequest request = HttpWebRequest.CreateHttp(remoteServer);
868867

869868
IAsyncResult asyncResult = request.BeginGetResponse(null, null);
870-
Assert.Throws<InvalidOperationException>(() =>
869+
Assert.Throws<ProtocolViolationException>(() =>
871870
{
872871
request.BeginGetRequestStream(null, null);
873872
});

0 commit comments

Comments
 (0)