aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/HttpServer
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
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 '')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs94
-rw-r--r--OpenSim/Framework/Servers/HttpServer/RestObjectPoster.cs28
-rw-r--r--OpenSim/Framework/Servers/HttpServer/RestObjectPosterResponse.cs29
-rw-r--r--OpenSim/Framework/Servers/HttpServer/RestSessionService.cs61
4 files changed, 119 insertions, 93 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 }
diff --git a/OpenSim/Framework/Servers/HttpServer/RestObjectPoster.cs b/OpenSim/Framework/Servers/HttpServer/RestObjectPoster.cs
index 48ced19..afe052f 100644
--- a/OpenSim/Framework/Servers/HttpServer/RestObjectPoster.cs
+++ b/OpenSim/Framework/Servers/HttpServer/RestObjectPoster.cs
@@ -52,23 +52,25 @@ namespace OpenSim.Framework.Servers.HttpServer
52 request.Method = verb; 52 request.Method = verb;
53 request.ContentType = "text/xml"; 53 request.ContentType = "text/xml";
54 54
55 MemoryStream buffer = new MemoryStream(); 55 using (MemoryStream buffer = new MemoryStream())
56 {
57 XmlWriterSettings settings = new XmlWriterSettings();
58 settings.Encoding = Encoding.UTF8;
56 59
57 XmlWriterSettings settings = new XmlWriterSettings(); 60 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
58 settings.Encoding = Encoding.UTF8; 61 {
62 XmlSerializer serializer = new XmlSerializer(type);
63 serializer.Serialize(writer, obj);
64 writer.Flush();
65 }
59 66
60 using (XmlWriter writer = XmlWriter.Create(buffer, settings)) 67 int length = (int)buffer.Length;
61 { 68 request.ContentLength = length;
62 XmlSerializer serializer = new XmlSerializer(type);
63 serializer.Serialize(writer, obj);
64 writer.Flush();
65 }
66 69
67 int length = (int) buffer.Length; 70 using (Stream requestStream = request.GetRequestStream())
68 request.ContentLength = length; 71 requestStream.Write(buffer.ToArray(), 0, length);
72 }
69 73
70 Stream requestStream = request.GetRequestStream();
71 requestStream.Write(buffer.ToArray(), 0, length);
72 // IAsyncResult result = request.BeginGetResponse(AsyncCallback, request); 74 // IAsyncResult result = request.BeginGetResponse(AsyncCallback, request);
73 request.BeginGetResponse(AsyncCallback, request); 75 request.BeginGetResponse(AsyncCallback, request);
74 } 76 }
diff --git a/OpenSim/Framework/Servers/HttpServer/RestObjectPosterResponse.cs b/OpenSim/Framework/Servers/HttpServer/RestObjectPosterResponse.cs
index 451745c..a911b9f 100644
--- a/OpenSim/Framework/Servers/HttpServer/RestObjectPosterResponse.cs
+++ b/OpenSim/Framework/Servers/HttpServer/RestObjectPosterResponse.cs
@@ -60,24 +60,25 @@ namespace OpenSim.Framework.Servers.HttpServer
60 request.ContentType = "text/xml"; 60 request.ContentType = "text/xml";
61 request.Timeout = 10000; 61 request.Timeout = 10000;
62 62
63 MemoryStream buffer = new MemoryStream(); 63 using (MemoryStream buffer = new MemoryStream())
64 {
65 XmlWriterSettings settings = new XmlWriterSettings();
66 settings.Encoding = Encoding.UTF8;
67
68 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
69 {
70 XmlSerializer serializer = new XmlSerializer(type);
71 serializer.Serialize(writer, obj);
72 writer.Flush();
73 }
64 74
65 XmlWriterSettings settings = new XmlWriterSettings(); 75 int length = (int)buffer.Length;
66 settings.Encoding = Encoding.UTF8; 76 request.ContentLength = length;
67 77
68 using (XmlWriter writer = XmlWriter.Create(buffer, settings)) 78 using (Stream requestStream = request.GetRequestStream())
69 { 79 requestStream.Write(buffer.ToArray(), 0, length);
70 XmlSerializer serializer = new XmlSerializer(type);
71 serializer.Serialize(writer, obj);
72 writer.Flush();
73 } 80 }
74 81
75 int length = (int) buffer.Length;
76 request.ContentLength = length;
77
78 Stream requestStream = request.GetRequestStream();
79 requestStream.Write(buffer.ToArray(), 0, length);
80 requestStream.Close();
81 // IAsyncResult result = request.BeginGetResponse(AsyncCallback, request); 82 // IAsyncResult result = request.BeginGetResponse(AsyncCallback, request);
82 request.BeginGetResponse(AsyncCallback, request); 83 request.BeginGetResponse(AsyncCallback, request);
83 } 84 }
diff --git a/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs b/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs
index 83c9848..ad69cd2 100644
--- a/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs
+++ b/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs
@@ -77,25 +77,24 @@ namespace OpenSim.Framework.Servers.HttpServer
77 request.ContentType = "text/xml"; 77 request.ContentType = "text/xml";
78 request.Timeout = 20000; 78 request.Timeout = 20000;
79 79
80 MemoryStream buffer = new MemoryStream(); 80 using (MemoryStream buffer = new MemoryStream())
81
82 XmlWriterSettings settings = new XmlWriterSettings();
83 settings.Encoding = Encoding.UTF8;
84
85 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
86 { 81 {
87 XmlSerializer serializer = new XmlSerializer(type); 82 XmlWriterSettings settings = new XmlWriterSettings();
88 serializer.Serialize(writer, sobj); 83 settings.Encoding = Encoding.UTF8;
89 writer.Flush();
90 }
91 84
92 int length = (int)buffer.Length; 85 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
93 request.ContentLength = length; 86 {
87 XmlSerializer serializer = new XmlSerializer(type);
88 serializer.Serialize(writer, sobj);
89 writer.Flush();
90 }
91
92 int length = (int)buffer.Length;
93 request.ContentLength = length;
94 94
95 Stream requestStream = request.GetRequestStream(); 95 using (Stream requestStream = request.GetRequestStream())
96 requestStream.Write(buffer.ToArray(), 0, length); 96 requestStream.Write(buffer.ToArray(), 0, length);
97 buffer.Close(); 97 }
98 requestStream.Close();
99 98
100 TResponse deserial = default(TResponse); 99 TResponse deserial = default(TResponse);
101 using (WebResponse resp = request.GetResponse()) 100 using (WebResponse resp = request.GetResponse())
@@ -133,25 +132,25 @@ namespace OpenSim.Framework.Servers.HttpServer
133 request.ContentType = "text/xml"; 132 request.ContentType = "text/xml";
134 request.Timeout = 10000; 133 request.Timeout = 10000;
135 134
136 MemoryStream buffer = new MemoryStream(); 135 using (MemoryStream buffer = new MemoryStream())
136 {
137 XmlWriterSettings settings = new XmlWriterSettings();
138 settings.Encoding = Encoding.UTF8;
139
140 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
141 {
142 XmlSerializer serializer = new XmlSerializer(type);
143 serializer.Serialize(writer, sobj);
144 writer.Flush();
145 }
137 146
138 XmlWriterSettings settings = new XmlWriterSettings(); 147 int length = (int)buffer.Length;
139 settings.Encoding = Encoding.UTF8; 148 request.ContentLength = length;
140 149
141 using (XmlWriter writer = XmlWriter.Create(buffer, settings)) 150 using (Stream requestStream = request.GetRequestStream())
142 { 151 requestStream.Write(buffer.ToArray(), 0, length);
143 XmlSerializer serializer = new XmlSerializer(type);
144 serializer.Serialize(writer, sobj);
145 writer.Flush();
146 } 152 }
147 buffer.Close();
148
149 int length = (int)buffer.Length;
150 request.ContentLength = length;
151 153
152 Stream requestStream = request.GetRequestStream();
153 requestStream.Write(buffer.ToArray(), 0, length);
154 requestStream.Close();
155 // IAsyncResult result = request.BeginGetResponse(AsyncCallback, request); 154 // IAsyncResult result = request.BeginGetResponse(AsyncCallback, request);
156 request.BeginGetResponse(AsyncCallback, request); 155 request.BeginGetResponse(AsyncCallback, request);
157 } 156 }