aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-02-27 23:13:26 +0000
committerJustin Clark-Casey (justincc)2014-02-27 23:13:26 +0000
commit88b1fc138246866aaca91a0218dfddde1ca69252 (patch)
treeb3985ac9d7cd44a599d4c2d87c8abe127853d000
parentRemove long unused UntrustedWebRequest class (diff)
downloadopensim-SC-88b1fc138246866aaca91a0218dfddde1ca69252.zip
opensim-SC-88b1fc138246866aaca91a0218dfddde1ca69252.tar.gz
opensim-SC-88b1fc138246866aaca91a0218dfddde1ca69252.tar.bz2
opensim-SC-88b1fc138246866aaca91a0218dfddde1ca69252.tar.xz
Set up a StreamReader and call ReadToEnd() instead of using the GetStreamString() extension method
This eliminates some stream seeking that was never necessary and makes disposable of the StreamReader consistent with other code
-rw-r--r--OpenSim/Framework/WebUtil.cs54
1 files changed, 13 insertions, 41 deletions
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs
index 6b39345..c7f1bdb 100644
--- a/OpenSim/Framework/WebUtil.cs
+++ b/OpenSim/Framework/WebUtil.cs
@@ -265,10 +265,12 @@ namespace OpenSim.Framework
265 { 265 {
266 using (Stream responseStream = response.GetResponseStream()) 266 using (Stream responseStream = response.GetResponseStream())
267 { 267 {
268 string responseStr = null; 268 using (StreamReader reader = new StreamReader(responseStream))
269 responseStr = responseStream.GetStreamString(); 269 {
270 // m_log.DebugFormat("[WEB UTIL]: <{0}> response is <{1}>",reqnum,responseStr); 270 string responseStr = reader.ReadToEnd();
271 return CanonicalizeResults(responseStr); 271 // m_log.DebugFormat("[WEB UTIL]: <{0}> response is <{1}>",reqnum,responseStr);
272 return CanonicalizeResults(responseStr);
273 }
272 } 274 }
273 } 275 }
274 } 276 }
@@ -426,12 +428,14 @@ namespace OpenSim.Framework
426 { 428 {
427 using (Stream responseStream = response.GetResponseStream()) 429 using (Stream responseStream = response.GetResponseStream())
428 { 430 {
429 string responseStr = null; 431 using (StreamReader reader = new StreamReader(responseStream))
432 {
433 string responseStr = reader.ReadToEnd();
434 OSD responseOSD = OSDParser.Deserialize(responseStr);
430 435
431 responseStr = responseStream.GetStreamString(); 436 if (responseOSD.Type == OSDType.Map)
432 OSD responseOSD = OSDParser.Deserialize(responseStr); 437 return (OSDMap)responseOSD;
433 if (responseOSD.Type == OSDType.Map) 438 }
434 return (OSDMap)responseOSD;
435 } 439 }
436 } 440 }
437 } 441 }
@@ -645,38 +649,6 @@ namespace OpenSim.Framework
645 return totalCopiedBytes; 649 return totalCopiedBytes;
646 } 650 }
647 651
648 /// <summary>
649 /// Converts an entire stream to a string, regardless of current stream
650 /// position
651 /// </summary>
652 /// <param name="stream">The stream to convert to a string</param>
653 /// <returns></returns>
654 /// <remarks>When this method is done, the stream position will be
655 /// reset to its previous position before this method was called</remarks>
656 public static string GetStreamString(this Stream stream)
657 {
658 string value = null;
659
660 if (stream != null && stream.CanRead)
661 {
662 long rewindPos = -1;
663
664 if (stream.CanSeek)
665 {
666 rewindPos = stream.Position;
667 stream.Seek(0, SeekOrigin.Begin);
668 }
669
670 StreamReader reader = new StreamReader(stream);
671 value = reader.ReadToEnd();
672
673 if (rewindPos >= 0)
674 stream.Seek(rewindPos, SeekOrigin.Begin);
675 }
676
677 return value;
678 }
679
680 #endregion Stream 652 #endregion Stream
681 653
682 public class QBasedComparer : IComparer 654 public class QBasedComparer : IComparer