aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/WebUtil.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/WebUtil.cs')
-rw-r--r--OpenSim/Framework/WebUtil.cs113
1 files changed, 105 insertions, 8 deletions
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs
index 70fab77..e614fd5 100644
--- a/OpenSim/Framework/WebUtil.cs
+++ b/OpenSim/Framework/WebUtil.cs
@@ -45,6 +45,8 @@ using Nwc.XmlRpc;
45using OpenMetaverse.StructuredData; 45using OpenMetaverse.StructuredData;
46using XMLResponseHelper = OpenSim.Framework.SynchronousRestObjectRequester.XMLResponseHelper; 46using XMLResponseHelper = OpenSim.Framework.SynchronousRestObjectRequester.XMLResponseHelper;
47 47
48using OpenSim.Framework.ServiceAuth;
49
48namespace OpenSim.Framework 50namespace OpenSim.Framework
49{ 51{
50 /// <summary> 52 /// <summary>
@@ -773,6 +775,13 @@ namespace OpenSim.Framework
773 string requestUrl, TRequest obj, Action<TResponse> action, 775 string requestUrl, TRequest obj, Action<TResponse> action,
774 int maxConnections) 776 int maxConnections)
775 { 777 {
778 MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, action, maxConnections, null);
779 }
780
781 public static void MakeRequest<TRequest, TResponse>(string verb,
782 string requestUrl, TRequest obj, Action<TResponse> action,
783 int maxConnections, IServiceAuth auth)
784 {
776 int reqnum = WebUtil.RequestNumber++; 785 int reqnum = WebUtil.RequestNumber++;
777 786
778 if (WebUtil.DebugLevel >= 3) 787 if (WebUtil.DebugLevel >= 3)
@@ -786,6 +795,10 @@ namespace OpenSim.Framework
786 795
787 WebRequest request = WebRequest.Create(requestUrl); 796 WebRequest request = WebRequest.Create(requestUrl);
788 HttpWebRequest ht = (HttpWebRequest)request; 797 HttpWebRequest ht = (HttpWebRequest)request;
798
799 if (auth != null)
800 auth.AddAuthorization(ht.Headers);
801
789 if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections) 802 if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections)
790 ht.ServicePoint.ConnectionLimit = maxConnections; 803 ht.ServicePoint.ConnectionLimit = maxConnections;
791 804
@@ -969,7 +982,7 @@ namespace OpenSim.Framework
969 /// 982 ///
970 /// <exception cref="System.Net.WebException">Thrown if we encounter a network issue while posting 983 /// <exception cref="System.Net.WebException">Thrown if we encounter a network issue while posting
971 /// the request. You'll want to make sure you deal with this as they're not uncommon</exception> 984 /// the request. You'll want to make sure you deal with this as they're not uncommon</exception>
972 public static string MakeRequest(string verb, string requestUrl, string obj, int timeoutsecs) 985 public static string MakeRequest(string verb, string requestUrl, string obj, int timeoutsecs, IServiceAuth auth)
973 { 986 {
974 int reqnum = WebUtil.RequestNumber++; 987 int reqnum = WebUtil.RequestNumber++;
975 988
@@ -984,6 +997,10 @@ namespace OpenSim.Framework
984 request.Method = verb; 997 request.Method = verb;
985 if (timeoutsecs > 0) 998 if (timeoutsecs > 0)
986 request.Timeout = timeoutsecs * 1000; 999 request.Timeout = timeoutsecs * 1000;
1000
1001 if (auth != null)
1002 auth.AddAuthorization(request.Headers);
1003
987 string respstring = String.Empty; 1004 string respstring = String.Empty;
988 1005
989 using (MemoryStream buffer = new MemoryStream()) 1006 using (MemoryStream buffer = new MemoryStream())
@@ -1068,10 +1085,20 @@ namespace OpenSim.Framework
1068 return respstring; 1085 return respstring;
1069 } 1086 }
1070 1087
1088 public static string MakeRequest(string verb, string requestUrl, string obj, int timeoutsecs)
1089 {
1090 return MakeRequest(verb, requestUrl, obj, timeoutsecs, null);
1091 }
1092
1071 public static string MakeRequest(string verb, string requestUrl, string obj) 1093 public static string MakeRequest(string verb, string requestUrl, string obj)
1072 { 1094 {
1073 return MakeRequest(verb, requestUrl, obj, -1); 1095 return MakeRequest(verb, requestUrl, obj, -1);
1074 } 1096 }
1097
1098 public static string MakeRequest(string verb, string requestUrl, string obj, IServiceAuth auth)
1099 {
1100 return MakeRequest(verb, requestUrl, obj, -1, auth);
1101 }
1075 } 1102 }
1076 1103
1077 public class SynchronousRestObjectRequester 1104 public class SynchronousRestObjectRequester
@@ -1085,23 +1112,76 @@ namespace OpenSim.Framework
1085 /// </summary> 1112 /// </summary>
1086 /// <param name="verb"></param> 1113 /// <param name="verb"></param>
1087 /// <param name="requestUrl"></param> 1114 /// <param name="requestUrl"></param>
1088 /// <param name="obj"> </param> 1115 /// <param name="obj"></param>
1089 /// <returns></returns> 1116 /// <returns>
1090 /// 1117 /// The response. If there was an internal exception, then the default(TResponse) is returned.
1091 /// <exception cref="System.Net.WebException">Thrown if we encounter a network issue while posting 1118 /// </returns>
1092 /// the request. You'll want to make sure you deal with this as they're not uncommon</exception>
1093 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj) 1119 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj)
1094 { 1120 {
1095 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, 0); 1121 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, 0);
1096 } 1122 }
1097 1123
1124 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, IServiceAuth auth)
1125 {
1126 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, 0, auth);
1127 }
1128 /// <summary>
1129 /// Perform a synchronous REST request.
1130 /// </summary>
1131 /// <param name="verb"></param>
1132 /// <param name="requestUrl"></param>
1133 /// <param name="obj"></param>
1134 /// <param name="pTimeout">
1135 /// Request timeout in milliseconds. Timeout.Infinite indicates no timeout. If 0 is passed then the default HttpWebRequest timeout is used (100 seconds)
1136 /// </param>
1137 /// <returns>
1138 /// The response. If there was an internal exception or the request timed out,
1139 /// then the default(TResponse) is returned.
1140 /// </returns>
1098 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, int pTimeout) 1141 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, int pTimeout)
1099 { 1142 {
1100 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, pTimeout, 0); 1143 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, pTimeout, 0);
1101 } 1144 }
1102 1145
1146 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, int pTimeout, IServiceAuth auth)
1147 {
1148 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, pTimeout, 0, auth);
1149 }
1150
1151 /// Perform a synchronous REST request.
1152 /// </summary>
1153 /// <param name="verb"></param>
1154 /// <param name="requestUrl"></param>
1155 /// <param name="obj"></param>
1156 /// <param name="pTimeout">
1157 /// Request timeout in milliseconds. Timeout.Infinite indicates no timeout. If 0 is passed then the default HttpWebRequest timeout is used (100 seconds)
1158 /// </param>
1159 /// <param name="maxConnections"></param>
1160 /// <returns>
1161 /// The response. If there was an internal exception or the request timed out,
1162 /// then the default(TResponse) is returned.
1163 /// </returns>
1103 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, int pTimeout, int maxConnections) 1164 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, int pTimeout, int maxConnections)
1104 { 1165 {
1166 return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, pTimeout, maxConnections, null);
1167 }
1168
1169 /// <summary>
1170 /// Perform a synchronous REST request.
1171 /// </summary>
1172 /// <param name="verb"></param>
1173 /// <param name="requestUrl"></param>
1174 /// <param name="obj"></param>
1175 /// <param name="pTimeout">
1176 /// Request timeout in milliseconds. Timeout.Infinite indicates no timeout. If 0 is passed then the default HttpWebRequest timeout is used (100 seconds)
1177 /// </param>
1178 /// <param name="maxConnections"></param>
1179 /// <returns>
1180 /// The response. If there was an internal exception or the request timed out,
1181 /// then the default(TResponse) is returned.
1182 /// </returns>
1183 public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, int pTimeout, int maxConnections, IServiceAuth auth)
1184 {
1105 int reqnum = WebUtil.RequestNumber++; 1185 int reqnum = WebUtil.RequestNumber++;
1106 1186
1107 if (WebUtil.DebugLevel >= 3) 1187 if (WebUtil.DebugLevel >= 3)
@@ -1116,6 +1196,13 @@ namespace OpenSim.Framework
1116 1196
1117 WebRequest request = WebRequest.Create(requestUrl); 1197 WebRequest request = WebRequest.Create(requestUrl);
1118 HttpWebRequest ht = (HttpWebRequest)request; 1198 HttpWebRequest ht = (HttpWebRequest)request;
1199
1200 if (auth != null)
1201 auth.AddAuthorization(ht.Headers);
1202
1203 if (pTimeout != 0)
1204 ht.Timeout = pTimeout;
1205
1119 if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections) 1206 if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections)
1120 ht.ServicePoint.ConnectionLimit = maxConnections; 1207 ht.ServicePoint.ConnectionLimit = maxConnections;
1121 1208
@@ -1191,8 +1278,18 @@ namespace OpenSim.Framework
1191 { 1278 {
1192 using (HttpWebResponse hwr = (HttpWebResponse)e.Response) 1279 using (HttpWebResponse hwr = (HttpWebResponse)e.Response)
1193 { 1280 {
1194 if (hwr != null && hwr.StatusCode == HttpStatusCode.NotFound) 1281 if (hwr != null)
1195 return deserial; 1282 {
1283 if (hwr.StatusCode == HttpStatusCode.NotFound)
1284 return deserial;
1285 if (hwr.StatusCode == HttpStatusCode.Unauthorized)
1286 {
1287 m_log.Error(string.Format(
1288 "[SynchronousRestObjectRequester]: Web request {0} requires authentication ",
1289 requestUrl));
1290 return deserial;
1291 }
1292 }
1196 else 1293 else
1197 m_log.Error(string.Format( 1294 m_log.Error(string.Format(
1198 "[SynchronousRestObjectRequester]: WebException for {0} {1} {2} ", 1295 "[SynchronousRestObjectRequester]: WebException for {0} {1} {2} ",