diff options
-rw-r--r-- | OpenSim/Framework/WebUtil.cs | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 20d30b5..89ccb5d 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs | |||
@@ -1334,16 +1334,42 @@ namespace OpenSim.Framework | |||
1334 | public static TResponse LogAndDeserialize<TRequest, TResponse>(int reqnum, Stream respStream, long contentLength) | 1334 | public static TResponse LogAndDeserialize<TRequest, TResponse>(int reqnum, Stream respStream, long contentLength) |
1335 | { | 1335 | { |
1336 | XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); | 1336 | XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); |
1337 | |||
1338 | if (WebUtil.DebugLevel >= 5) | 1337 | if (WebUtil.DebugLevel >= 5) |
1339 | { | 1338 | { |
1340 | byte[] data = new byte[contentLength]; | 1339 | const int blockLength = 4096; |
1341 | Util.ReadStream(respStream, data); | 1340 | byte[] dataBuffer = new byte[blockLength]; |
1341 | int curcount; | ||
1342 | using (MemoryStream ms = new MemoryStream(4 * blockLength)) | ||
1343 | { | ||
1344 | if(contentLength == -1) | ||
1345 | { | ||
1346 | while (true) | ||
1347 | { | ||
1348 | curcount = respStream.Read(dataBuffer, 0, blockLength); | ||
1349 | if (curcount <= 0) | ||
1350 | break; | ||
1351 | ms.Write(dataBuffer, 0, curcount); | ||
1352 | } | ||
1353 | } | ||
1354 | else | ||
1355 | { | ||
1356 | int remaining = (int)contentLength; | ||
1357 | while (remaining > 0) | ||
1358 | { | ||
1359 | curcount = respStream.Read(dataBuffer, 0, remaining); | ||
1360 | if (curcount <= 0) | ||
1361 | throw new EndOfStreamException(String.Format("End of stream reached with {0} bytes left to read", remaining)); | ||
1362 | ms.Write(dataBuffer, 0, curcount); | ||
1363 | remaining -= curcount; | ||
1364 | } | ||
1365 | } | ||
1342 | 1366 | ||
1343 | WebUtil.LogResponseDetail(reqnum, System.Text.Encoding.UTF8.GetString(data)); | 1367 | dataBuffer = ms.ToArray(); |
1368 | WebUtil.LogResponseDetail(reqnum, System.Text.Encoding.UTF8.GetString(dataBuffer)); | ||
1344 | 1369 | ||
1345 | using (MemoryStream temp = new MemoryStream(data)) | 1370 | ms.Position = 0; |
1346 | return (TResponse)deserializer.Deserialize(temp); | 1371 | return (TResponse)deserializer.Deserialize(ms); |
1372 | } | ||
1347 | } | 1373 | } |
1348 | else | 1374 | else |
1349 | { | 1375 | { |
@@ -1427,6 +1453,5 @@ namespace OpenSim.Framework | |||
1427 | } | 1453 | } |
1428 | } | 1454 | } |
1429 | } | 1455 | } |
1430 | |||
1431 | } | 1456 | } |
1432 | } | 1457 | } |