aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
diff options
context:
space:
mode:
authorOren Hurvitz2014-06-01 17:39:11 +0300
committerOren Hurvitz2014-07-21 08:30:03 +0100
commit99ac770abbe3a95887c4b10c82f3985aa878eeef (patch)
tree8c946dab083dd50a352f3861415eca43185d8d95 /OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
parentSet "[Terrain]SendTerrainUpdatesByViewDistance=true" by default. (diff)
downloadopensim-SC-99ac770abbe3a95887c4b10c82f3985aa878eeef.zip
opensim-SC-99ac770abbe3a95887c4b10c82f3985aa878eeef.tar.gz
opensim-SC-99ac770abbe3a95887c4b10c82f3985aa878eeef.tar.bz2
opensim-SC-99ac770abbe3a95887c4b10c82f3985aa878eeef.tar.xz
Close streams immediately when we finish using them
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs94
1 files changed, 59 insertions, 35 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
index b92c25b..093855c 100644
--- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
@@ -832,28 +832,40 @@ namespace OpenSim.Framework.Servers.HttpServer
832 return; // never log these; they're just binary data 832 return; // never log these; they're just binary data
833 833
834 Stream inputStream = Util.Copy(request.InputStream); 834 Stream inputStream = Util.Copy(request.InputStream);
835 835 Stream innerStream = null;
836 if ((request.Headers["Content-Encoding"] == "gzip") || (request.Headers["X-Content-Encoding"] == "gzip")) 836 try
837 inputStream = new GZipStream(inputStream, System.IO.Compression.CompressionMode.Decompress);
838
839 using (StreamReader reader = new StreamReader(inputStream, Encoding.UTF8))
840 { 837 {
841 string output; 838 if ((request.Headers["Content-Encoding"] == "gzip") || (request.Headers["X-Content-Encoding"] == "gzip"))
842
843 if (DebugLevel == 5)
844 { 839 {
845 char[] chars = new char[WebUtil.MaxRequestDiagLength + 1]; // +1 so we know to add "..." only if needed 840 innerStream = inputStream;
846 int len = reader.Read(chars, 0, WebUtil.MaxRequestDiagLength + 1); 841 inputStream = new GZipStream(innerStream, System.IO.Compression.CompressionMode.Decompress);
847 output = new string(chars, 0, Math.Min(len, WebUtil.MaxRequestDiagLength));
848 if (len > WebUtil.MaxRequestDiagLength)
849 output += "...";
850 } 842 }
851 else 843
844 using (StreamReader reader = new StreamReader(inputStream, Encoding.UTF8))
852 { 845 {
853 output = reader.ReadToEnd(); 846 string output;
854 }
855 847
856 m_log.DebugFormat("[LOGHTTP] {0}", Util.BinaryToASCII(output)); 848 if (DebugLevel == 5)
849 {
850 char[] chars = new char[WebUtil.MaxRequestDiagLength + 1]; // +1 so we know to add "..." only if needed
851 int len = reader.Read(chars, 0, WebUtil.MaxRequestDiagLength + 1);
852 output = new string(chars, 0, Math.Min(len, WebUtil.MaxRequestDiagLength));
853 if (len > WebUtil.MaxRequestDiagLength)
854 output += "...";
855 }
856 else
857 {
858 output = reader.ReadToEnd();
859 }
860
861 m_log.DebugFormat("[LOGHTTP] {0}", Util.BinaryToASCII(output));
862 }
863 }
864 finally
865 {
866 if (innerStream != null)
867 innerStream.Dispose();
868 inputStream.Dispose();
857 } 869 }
858 } 870 }
859 871
@@ -981,19 +993,33 @@ namespace OpenSim.Framework.Servers.HttpServer
981 /// <param name="response"></param> 993 /// <param name="response"></param>
982 private byte[] HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response) 994 private byte[] HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response)
983 { 995 {
984 Stream requestStream = request.InputStream; 996 String requestBody;
985 997
986 if ((request.Headers["Content-Encoding"] == "gzip") || (request.Headers["X-Content-Encoding"] == "gzip")) 998 Stream requestStream = request.InputStream;
987 requestStream = new GZipStream(requestStream, System.IO.Compression.CompressionMode.Decompress); 999 Stream innerStream = null;
1000 try
1001 {
1002 if ((request.Headers["Content-Encoding"] == "gzip") || (request.Headers["X-Content-Encoding"] == "gzip"))
1003 {
1004 innerStream = requestStream;
1005 requestStream = new GZipStream(innerStream, System.IO.Compression.CompressionMode.Decompress);
1006 }
988 1007
989 Encoding encoding = Encoding.UTF8; 1008 using (StreamReader reader = new StreamReader(requestStream, Encoding.UTF8))
990 StreamReader reader = new StreamReader(requestStream, encoding); 1009 {
1010 requestBody = reader.ReadToEnd();
1011 }
1012 }
1013 finally
1014 {
1015 if (innerStream != null)
1016 innerStream.Dispose();
1017 requestStream.Dispose();
1018 }
991 1019
992 string requestBody = reader.ReadToEnd();
993 reader.Close();
994 requestStream.Close();
995 //m_log.Debug(requestBody); 1020 //m_log.Debug(requestBody);
996 requestBody = requestBody.Replace("<base64></base64>", ""); 1021 requestBody = requestBody.Replace("<base64></base64>", "");
1022
997 string responseString = String.Empty; 1023 string responseString = String.Empty;
998 XmlRpcRequest xmlRprcRequest = null; 1024 XmlRpcRequest xmlRprcRequest = null;
999 1025
@@ -1089,18 +1115,16 @@ namespace OpenSim.Framework.Servers.HttpServer
1089 1115
1090 response.ContentType = "text/xml"; 1116 response.ContentType = "text/xml";
1091 using (MemoryStream outs = new MemoryStream()) 1117 using (MemoryStream outs = new MemoryStream())
1118 using (XmlTextWriter writer = new XmlTextWriter(outs, Encoding.UTF8))
1092 { 1119 {
1093 using (XmlTextWriter writer = new XmlTextWriter(outs, Encoding.UTF8)) 1120 writer.Formatting = Formatting.None;
1121 XmlRpcResponseSerializer.Singleton.Serialize(writer, xmlRpcResponse);
1122 writer.Flush();
1123 outs.Flush();
1124 outs.Position = 0;
1125 using (StreamReader sr = new StreamReader(outs))
1094 { 1126 {
1095 writer.Formatting = Formatting.None; 1127 responseString = sr.ReadToEnd();
1096 XmlRpcResponseSerializer.Singleton.Serialize(writer, xmlRpcResponse);
1097 writer.Flush();
1098 outs.Flush();
1099 outs.Position = 0;
1100 using (StreamReader sr = new StreamReader(outs))
1101 {
1102 responseString = sr.ReadToEnd();
1103 }
1104 } 1128 }
1105 } 1129 }
1106 } 1130 }