Chunked read error reporting improvement
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 10 Feb 2012 07:14:36 +0000 (02:14 -0500)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 10 Feb 2012 07:14:36 +0000 (02:14 -0500)
Reset the chunked read variables before reading the chunk size and
provide a better error in case of a protocol problem.

mcs/class/System/System.Net/ChunkStream.cs
mcs/class/System/System.Net/ChunkedInputStream.cs

index 0edb422370b1d6c7e5d81bde4d48970bd4191cae..dd1e49cdf8b928d86322d6befaf3a1970494e312 100644 (file)
@@ -201,6 +201,8 @@ namespace System.Net
                
                State GetChunkSize (byte [] buffer, ref int offset, int size)
                {
+                       chunkRead = 0;
+                       chunkSize = 0;
                        char c = '\0';
                        while (offset < size) {
                                c = (char) buffer [offset++];
@@ -246,7 +248,7 @@ namespace System.Net
                        } catch (Exception) {
                                ThrowProtocolViolation ("Cannot parse chunk size.");
                        }
-                       
+
                        if (chunkSize == 0) {
                                trailerState = 2;
                                return State.Trailer;
index 2b714ca942e0211c0ab993aee59e359ebfb521cd..4c7c744140b2f5becaab29587a1de91eb4ce1e45 100644 (file)
@@ -159,7 +159,7 @@ namespace System.Net {
                                ares.AsyncWaitHandle.WaitOne ();
 
                        if (my_ares.Error != null)
-                               throw new HttpListenerException (400, "I/O operation aborted.");
+                               throw new HttpListenerException (400, "I/O operation aborted: " + my_ares.Error.Message);
 
                        return my_ares.Count;
                }