diff options
author | Filip Navara <filip.navara@gmail.com> | 2017-03-23 14:36:58 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2017-03-23 21:30:57 +0300 |
commit | b9448d532091667fb600d537373c9558452e897e (patch) | |
tree | ae85d146ca5f976bc1a145c07ec0d410bfb4a3a6 /mcs/class/System/Test | |
parent | e6f020d39018405fe98758cbf792f2daa3540618 (diff) |
Add test for AutomaticDecompression behaviour
Test that HttpWebRequest.AutomaticDecompression actually performs the
decompression and that it removes the Content-Encoding header. Also fix
the value of Content-Encoding for other tests to follow the HTTP
specification.
Diffstat (limited to 'mcs/class/System/Test')
-rw-r--r-- | mcs/class/System/Test/System.Net/HttpWebResponseTest.cs | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/mcs/class/System/Test/System.Net/HttpWebResponseTest.cs b/mcs/class/System/Test/System.Net/HttpWebResponseTest.cs index b2c8e90488c..ffa7f6359e5 100644 --- a/mcs/class/System/Test/System.Net/HttpWebResponseTest.cs +++ b/mcs/class/System/Test/System.Net/HttpWebResponseTest.cs @@ -286,7 +286,7 @@ namespace MonoTests.System.Net WebHeaderCollection headers = resp.Headers; Assert.AreEqual (6, headers.Count, "#1"); Assert.AreEqual ("9", headers ["Content-Length"], "#2"); - Assert.AreEqual ("utf-8", headers ["Content-Encoding"], "#3"); + Assert.AreEqual ("identity", headers ["Content-Encoding"], "#3"); Assert.AreEqual ("text/xml; charset=UTF-8", headers ["Content-Type"], "#4"); Assert.AreEqual ("Wed, 08 Jan 2003 23:11:55 GMT", headers ["Last-Modified"], "#5"); Assert.AreEqual ("UserID=Miguel,StoreProfile=true", headers ["Set-Cookie"], "#6"); @@ -510,7 +510,7 @@ namespace MonoTests.System.Net sw.WriteLine ("HTTP/1.0 200 OK"); sw.WriteLine ("Server: Mono/Test"); sw.WriteLine ("Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT"); - sw.WriteLine ("Content-Encoding: " + Encoding.UTF8.WebName); + sw.WriteLine ("Content-Encoding: identity"); sw.WriteLine ("Content-Type: text/xml; charset=UTF-8"); sw.WriteLine ("Content-Length: 9"); sw.WriteLine ("Set-Cookie: UserID=Miguel"); @@ -521,6 +521,30 @@ namespace MonoTests.System.Net return Encoding.UTF8.GetBytes (sw.ToString ()); } + + internal static byte [] GzipResponseHandler (Socket socket) + { + StringWriter sw = new StringWriter (); + sw.NewLine = "\r\n"; + sw.WriteLine ("HTTP/1.0 200 OK"); + sw.WriteLine ("Server: Mono/Test"); + sw.WriteLine ("Content-Encoding: gzip"); + sw.WriteLine ("Content-Type: text/xml; charset=UTF-8"); + sw.WriteLine (); + sw.Flush (); + + var gzipDummyXml = new byte[] { + 0x1f, 0x8b, 0x08, 0x08, 0xb6, 0xb1, 0xd3, 0x58, 0x00, 0x03, 0x74, 0x65, 0x73, 0x74, 0x67, 0x7a, + 0x00, 0xb3, 0x49, 0x29, 0xcd, 0xcd, 0xad, 0x54, 0xd0, 0xb7, 0x03, 0x00, 0xed, 0x55, 0x32, 0xec, + 0x09, 0x00, 0x00, 0x00 }; + var header = Encoding.UTF8.GetBytes (sw.ToString ()); + + var response = new byte[gzipDummyXml.Length + header.Length]; + header.CopyTo(response, 0); + gzipDummyXml.CopyTo(response, header.Length); + + return response; + } } [TestFixture] @@ -1193,5 +1217,38 @@ namespace MonoTests.System.Net } } } + + + [Test] +#if FEATURE_NO_BSD_SOCKETS + [ExpectedException (typeof (PlatformNotSupportedException))] +#endif + public void AutomaticDecompression () + { + IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint(); + string url = "http://" + ep.ToString () + "/test/"; + + using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.GzipResponseHandler (s))) { + HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "GET"; + req.Timeout = 2000; + req.ReadWriteTimeout = 2000; + req.KeepAlive = false; + req.AutomaticDecompression = DecompressionMethods.GZip; + + using (HttpWebResponse resp = (HttpWebResponse) req.GetResponse ()) { + Stream rs = resp.GetResponseStream (); + byte [] buffer = new byte [24]; + try { + // read full response + Assert.AreEqual (9, rs.Read (buffer, 0, buffer.Length)); + Assert.IsNull (resp.Headers[HttpRequestHeader.ContentEncoding]); + } finally { + rs.Close (); + req.Abort (); + } + } + } + } } } |