aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/WebUtil.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/WebUtil.cs64
1 files changed, 61 insertions, 3 deletions
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs
index bf57fd4..dfa37ca 100644
--- a/OpenSim/Framework/WebUtil.cs
+++ b/OpenSim/Framework/WebUtil.cs
@@ -151,6 +151,39 @@ namespace OpenSim.Framework
151 } 151 }
152 } 152 }
153 153
154 public static void LogOutgoingDetail(Stream outputStream)
155 {
156 using (StreamReader reader = new StreamReader(Util.Copy(outputStream), Encoding.UTF8))
157 {
158 string output;
159
160 if (DebugLevel == 5)
161 {
162 const int sampleLength = 80;
163 char[] sampleChars = new char[sampleLength];
164 reader.Read(sampleChars, 0, sampleLength);
165 output = new string(sampleChars);
166 }
167 else
168 {
169 output = reader.ReadToEnd();
170 }
171
172 LogOutgoingDetail(output);
173 }
174 }
175
176 public static void LogOutgoingDetail(string output)
177 {
178 if (DebugLevel == 5)
179 {
180 output = output.Substring(0, 80);
181 output = output + "...";
182 }
183
184 m_log.DebugFormat("[WEB UTIL]: {0}", output.Replace("\n", @"\n"));
185 }
186
154 private static OSDMap ServiceOSDRequestWorker(string url, OSDMap data, string method, int timeout, bool compressed) 187 private static OSDMap ServiceOSDRequestWorker(string url, OSDMap data, string method, int timeout, bool compressed)
155 { 188 {
156 int reqnum = RequestNumber++; 189 int reqnum = RequestNumber++;
@@ -178,7 +211,11 @@ namespace OpenSim.Framework
178 // If there is some input, write it into the request 211 // If there is some input, write it into the request
179 if (data != null) 212 if (data != null)
180 { 213 {
181 strBuffer = OSDParser.SerializeJsonString(data); 214 strBuffer = OSDParser.SerializeJsonString(data);
215
216 if (DebugLevel >= 5)
217 LogOutgoingDetail(strBuffer);
218
182 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer); 219 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer);
183 220
184 if (compressed) 221 if (compressed)
@@ -358,6 +395,10 @@ namespace OpenSim.Framework
358 if (data != null) 395 if (data != null)
359 { 396 {
360 queryString = BuildQueryString(data); 397 queryString = BuildQueryString(data);
398
399 if (DebugLevel >= 5)
400 LogOutgoingDetail(queryString);
401
361 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(queryString); 402 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(queryString);
362 403
363 request.ContentLength = buffer.Length; 404 request.ContentLength = buffer.Length;
@@ -769,6 +810,9 @@ namespace OpenSim.Framework
769 int length = (int)buffer.Length; 810 int length = (int)buffer.Length;
770 request.ContentLength = length; 811 request.ContentLength = length;
771 812
813 if (WebUtil.DebugLevel >= 5)
814 WebUtil.LogOutgoingDetail(buffer);
815
772 request.BeginGetRequestStream(delegate(IAsyncResult res) 816 request.BeginGetRequestStream(delegate(IAsyncResult res)
773 { 817 {
774 Stream requestStream = request.EndGetRequestStream(res); 818 Stream requestStream = request.EndGetRequestStream(res);
@@ -928,11 +972,12 @@ namespace OpenSim.Framework
928 /// <param name="verb"></param> 972 /// <param name="verb"></param>
929 /// <param name="requestUrl"></param> 973 /// <param name="requestUrl"></param>
930 /// <param name="obj"> </param> 974 /// <param name="obj"> </param>
975 /// <param name="timeoutsecs"> </param>
931 /// <returns></returns> 976 /// <returns></returns>
932 /// 977 ///
933 /// <exception cref="System.Net.WebException">Thrown if we encounter a network issue while posting 978 /// <exception cref="System.Net.WebException">Thrown if we encounter a network issue while posting
934 /// the request. You'll want to make sure you deal with this as they're not uncommon</exception> 979 /// the request. You'll want to make sure you deal with this as they're not uncommon</exception>
935 public static string MakeRequest(string verb, string requestUrl, string obj) 980 public static string MakeRequest(string verb, string requestUrl, string obj, int timeoutsecs)
936 { 981 {
937 int reqnum = WebUtil.RequestNumber++; 982 int reqnum = WebUtil.RequestNumber++;
938 983
@@ -946,6 +991,8 @@ namespace OpenSim.Framework
946 991
947 WebRequest request = WebRequest.Create(requestUrl); 992 WebRequest request = WebRequest.Create(requestUrl);
948 request.Method = verb; 993 request.Method = verb;
994 if (timeoutsecs > 0)
995 request.Timeout = timeoutsecs * 1000;
949 string respstring = String.Empty; 996 string respstring = String.Empty;
950 997
951 int tickset = Util.EnvironmentTickCountSubtract(tickstart); 998 int tickset = Util.EnvironmentTickCountSubtract(tickstart);
@@ -966,6 +1013,9 @@ namespace OpenSim.Framework
966 length = (int)obj.Length; 1013 length = (int)obj.Length;
967 request.ContentLength = length; 1014 request.ContentLength = length;
968 1015
1016 if (WebUtil.DebugLevel >= 5)
1017 WebUtil.LogOutgoingDetail(buffer);
1018
969 Stream requestStream = null; 1019 Stream requestStream = null;
970 try 1020 try
971 { 1021 {
@@ -1039,6 +1089,11 @@ namespace OpenSim.Framework
1039 1089
1040 return respstring; 1090 return respstring;
1041 } 1091 }
1092
1093 public static string MakeRequest(string verb, string requestUrl, string obj)
1094 {
1095 return MakeRequest(verb, requestUrl, obj, -1);
1096 }
1042 } 1097 }
1043 1098
1044 public class SynchronousRestObjectRequester 1099 public class SynchronousRestObjectRequester
@@ -1111,6 +1166,9 @@ namespace OpenSim.Framework
1111 int length = (int)buffer.Length; 1166 int length = (int)buffer.Length;
1112 request.ContentLength = length; 1167 request.ContentLength = length;
1113 1168
1169 if (WebUtil.DebugLevel >= 5)
1170 WebUtil.LogOutgoingDetail(buffer);
1171
1114 Stream requestStream = null; 1172 Stream requestStream = null;
1115 try 1173 try
1116 { 1174 {
@@ -1213,4 +1271,4 @@ namespace OpenSim.Framework
1213 return deserial; 1271 return deserial;
1214 } 1272 }
1215 } 1273 }
1216} 1274} \ No newline at end of file