Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs
diff options
context:
space:
mode:
authormonojenkins <jo.shields+jenkins@xamarin.com>2015-12-15 20:43:22 +0300
committermonojenkins <jo.shields+jenkins@xamarin.com>2015-12-15 20:43:22 +0300
commit564fe71fa8cccb5a6cdbeaf713a2f1eaa7729593 (patch)
tree53accfad58e77ab685b9b9e64fb49ca559cd2f8d /mcs
parent42c503ad559541bd8a8b03b3c6d0b6693324da29 (diff)
parent10e5aba1550505184f094cc4329ce6a184551082 (diff)
Merge pull request #2338 from BogdanovKirill/httpwritefix3
[HttpConnection] Bug fix: HttpListener's "IgnoreWriteExceptions" property value is ignored when "Expect: 100-Continue" header set in request That problem was discussed previously here: https://github.com/mono/mono/pull/2300 I want to offer alternative solution now.
Diffstat (limited to 'mcs')
-rw-r--r--mcs/class/System/System.Net/HttpConnection.cs7
-rw-r--r--mcs/class/System/Test/System.Net/HttpListenerTest.cs49
2 files changed, 54 insertions, 2 deletions
diff --git a/mcs/class/System/System.Net/HttpConnection.cs b/mcs/class/System/System.Net/HttpConnection.cs
index 7adfdf8d956..2be693f5b16 100644
--- a/mcs/class/System/System.Net/HttpConnection.cs
+++ b/mcs/class/System/System.Net/HttpConnection.cs
@@ -209,8 +209,11 @@ namespace System.Net {
// TODO: can we get this stream before reading the input?
if (o_stream == null) {
HttpListener listener = context.Listener;
- bool ign = (listener == null) ? true : listener.IgnoreWriteExceptions;
- o_stream = new ResponseStream (stream, context.Response, ign);
+
+ if(listener == null)
+ return new ResponseStream (stream, context.Response, true);
+
+ o_stream = new ResponseStream (stream, context.Response, listener.IgnoreWriteExceptions);
}
return o_stream;
}
diff --git a/mcs/class/System/Test/System.Net/HttpListenerTest.cs b/mcs/class/System/Test/System.Net/HttpListenerTest.cs
index 5e9103a1038..589ec80e924 100644
--- a/mcs/class/System/Test/System.Net/HttpListenerTest.cs
+++ b/mcs/class/System/Test/System.Net/HttpListenerTest.cs
@@ -27,9 +27,11 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
+using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
+using System.Threading.Tasks;
using NUnit.Framework;
using MonoTests.Helpers;
@@ -531,6 +533,53 @@ namespace MonoTests.System.Net {
return clientEndPoint;
}
+
+ [Test]
+ public void HttpClientIsDisconnectedCheckForWriteException()
+ {
+ string uri = "http://localhost:" + NetworkHelpers.FindFreePort () + "/";
+
+ AutoResetEvent exceptionOccuredEvent = new AutoResetEvent (false);
+ HttpListener listener = new HttpListener {
+ IgnoreWriteExceptions = false
+ };
+ listener.Prefixes.Add (uri);
+ listener.Start ();
+ listener.BeginGetContext (result =>
+ {
+ HttpListenerContext context = listener.EndGetContext (result);
+ context.Response.SendChunked = true;
+ context.Request.InputStream.Close ();
+
+ var bytes = new byte [1024];
+ using(Stream outputStream = context.Response.OutputStream) {
+ try {
+ while (true)
+ outputStream.Write (bytes, 0, bytes.Length);
+ } catch {
+ exceptionOccuredEvent.Set ();
+ }
+ }
+ }, null);
+
+ Task.Factory.StartNew (() =>
+ {
+ var webRequest = (HttpWebRequest)WebRequest.Create (uri);
+ webRequest.Method = "POST";
+ webRequest.KeepAlive = false;
+ Stream requestStream = webRequest.GetRequestStream ();
+ requestStream.WriteByte (1);
+ requestStream.Close ();
+ using (WebResponse response = webRequest.GetResponse ())
+ using (Stream stream = response.GetResponseStream ()) {
+ byte[] clientBytes = new byte [1024];
+ Assert.IsNotNull (stream, "#01");
+ stream.Read (clientBytes, 0, clientBytes.Length);
+ }
+ });
+
+ Assert.IsTrue (exceptionOccuredEvent.WaitOne (15 * 1000), "#02");
+ }
}
}