OSDN Git Service

HTTPプロキシでchunked codingのchunk extensionとtrailerを破棄する
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Sun, 3 Jan 2016 14:30:42 +0000 (23:30 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Mon, 4 Jan 2016 13:31:27 +0000 (22:31 +0900)
KancolleSniffer/HttpProxy.cs

index 4f71d37..fa535b5 100644 (file)
@@ -522,10 +522,11 @@ namespace KancolleSniffer
                     var size = ReadLine();\r
                     if (size.Length < 3)\r
                         break;\r
+                    var ext = size.IndexOf(';');\r
+                    size = ext == -1 ? size.Substring(0, size.Length - 2) : size.Substring(0, ext);\r
                     int val;\r
-                    if (!int.TryParse(size.Substring(0, size.Length - 2),\r
-                        NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out val))\r
-                        break;\r
+                    if (!int.TryParse(size, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val))\r
+                        throw new HttpProxyAbort("Can't parse chunk size: " + size);\r
                     if (val == 0)\r
                     {\r
                         ReadLine();\r
@@ -536,6 +537,11 @@ namespace KancolleSniffer
                     buf.Write(chunk, 0, chunk.Length);\r
                     ReadLine();\r
                 }\r
+                string line;\r
+                do\r
+                {\r
+                    line = ReadLine();\r
+                } while (line != "" && line != "\r\n");\r
                 return buf.ToArray();\r
             }\r
 \r