mirror of
https://github.com/opensim/opensim.git
synced 2026-08-08 18:25:33 +08:00
Adds optional HTTP Basic Authentication to Robust service connectors.
This commit is contained in:
@@ -45,6 +45,8 @@ using Nwc.XmlRpc;
|
||||
using OpenMetaverse.StructuredData;
|
||||
using XMLResponseHelper = OpenSim.Framework.SynchronousRestObjectRequester.XMLResponseHelper;
|
||||
|
||||
using OpenSim.Framework.ServiceAuth;
|
||||
|
||||
namespace OpenSim.Framework
|
||||
{
|
||||
/// <summary>
|
||||
@@ -772,6 +774,13 @@ namespace OpenSim.Framework
|
||||
public static void MakeRequest<TRequest, TResponse>(string verb,
|
||||
string requestUrl, TRequest obj, Action<TResponse> action,
|
||||
int maxConnections)
|
||||
{
|
||||
MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, action, maxConnections, null);
|
||||
}
|
||||
|
||||
public static void MakeRequest<TRequest, TResponse>(string verb,
|
||||
string requestUrl, TRequest obj, Action<TResponse> action,
|
||||
int maxConnections, IServiceAuth auth)
|
||||
{
|
||||
int reqnum = WebUtil.RequestNumber++;
|
||||
|
||||
@@ -786,6 +795,10 @@ namespace OpenSim.Framework
|
||||
|
||||
WebRequest request = WebRequest.Create(requestUrl);
|
||||
HttpWebRequest ht = (HttpWebRequest)request;
|
||||
|
||||
if (auth != null)
|
||||
auth.AddAuthorization(ht.Headers);
|
||||
|
||||
if (maxConnections > 0 && ht.ServicePoint.ConnectionLimit < maxConnections)
|
||||
ht.ServicePoint.ConnectionLimit = maxConnections;
|
||||
|
||||
@@ -969,7 +982,7 @@ namespace OpenSim.Framework
|
||||
///
|
||||
/// <exception cref="System.Net.WebException">Thrown if we encounter a network issue while posting
|
||||
/// the request. You'll want to make sure you deal with this as they're not uncommon</exception>
|
||||
public static string MakeRequest(string verb, string requestUrl, string obj, int timeoutsecs)
|
||||
public static string MakeRequest(string verb, string requestUrl, string obj, int timeoutsecs, IServiceAuth auth)
|
||||
{
|
||||
int reqnum = WebUtil.RequestNumber++;
|
||||
|
||||
@@ -984,6 +997,10 @@ namespace OpenSim.Framework
|
||||
request.Method = verb;
|
||||
if (timeoutsecs > 0)
|
||||
request.Timeout = timeoutsecs * 1000;
|
||||
|
||||
if (auth != null)
|
||||
auth.AddAuthorization(request.Headers);
|
||||
|
||||
string respstring = String.Empty;
|
||||
|
||||
using (MemoryStream buffer = new MemoryStream())
|
||||
@@ -1068,10 +1085,20 @@ namespace OpenSim.Framework
|
||||
return respstring;
|
||||
}
|
||||
|
||||
public static string MakeRequest(string verb, string requestUrl, string obj, int timeoutsecs)
|
||||
{
|
||||
return MakeRequest(verb, requestUrl, obj, timeoutsecs, null);
|
||||
}
|
||||
|
||||
public static string MakeRequest(string verb, string requestUrl, string obj)
|
||||
{
|
||||
return MakeRequest(verb, requestUrl, obj, -1);
|
||||
}
|
||||
|
||||
public static string MakeRequest(string verb, string requestUrl, string obj, IServiceAuth auth)
|
||||
{
|
||||
return MakeRequest(verb, requestUrl, obj, -1, auth);
|
||||
}
|
||||
}
|
||||
|
||||
public class SynchronousRestObjectRequester
|
||||
@@ -1094,6 +1121,10 @@ namespace OpenSim.Framework
|
||||
return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, 0);
|
||||
}
|
||||
|
||||
public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, IServiceAuth auth)
|
||||
{
|
||||
return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, 0, auth);
|
||||
}
|
||||
/// <summary>
|
||||
/// Perform a synchronous REST request.
|
||||
/// </summary>
|
||||
@@ -1112,7 +1143,11 @@ namespace OpenSim.Framework
|
||||
return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, pTimeout, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, int pTimeout, IServiceAuth auth)
|
||||
{
|
||||
return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, pTimeout, 0, auth);
|
||||
}
|
||||
|
||||
/// Perform a synchronous REST request.
|
||||
/// </summary>
|
||||
/// <param name="verb"></param>
|
||||
@@ -1127,6 +1162,25 @@ namespace OpenSim.Framework
|
||||
/// then the default(TResponse) is returned.
|
||||
/// </returns>
|
||||
public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, int pTimeout, int maxConnections)
|
||||
{
|
||||
return MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, pTimeout, maxConnections, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform a synchronous REST request.
|
||||
/// </summary>
|
||||
/// <param name="verb"></param>
|
||||
/// <param name="requestUrl"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <param name="pTimeout">
|
||||
/// Request timeout in milliseconds. Timeout.Infinite indicates no timeout. If 0 is passed then the default HttpWebRequest timeout is used (100 seconds)
|
||||
/// </param>
|
||||
/// <param name="maxConnections"></param>
|
||||
/// <returns>
|
||||
/// The response. If there was an internal exception or the request timed out,
|
||||
/// then the default(TResponse) is returned.
|
||||
/// </returns>
|
||||
public static TResponse MakeRequest<TRequest, TResponse>(string verb, string requestUrl, TRequest obj, int pTimeout, int maxConnections, IServiceAuth auth)
|
||||
{
|
||||
int reqnum = WebUtil.RequestNumber++;
|
||||
|
||||
@@ -1143,6 +1197,9 @@ namespace OpenSim.Framework
|
||||
WebRequest request = WebRequest.Create(requestUrl);
|
||||
HttpWebRequest ht = (HttpWebRequest)request;
|
||||
|
||||
if (auth != null)
|
||||
auth.AddAuthorization(ht.Headers);
|
||||
|
||||
if (pTimeout != 0)
|
||||
ht.Timeout = pTimeout;
|
||||
|
||||
@@ -1221,8 +1278,18 @@ namespace OpenSim.Framework
|
||||
{
|
||||
using (HttpWebResponse hwr = (HttpWebResponse)e.Response)
|
||||
{
|
||||
if (hwr != null && hwr.StatusCode == HttpStatusCode.NotFound)
|
||||
return deserial;
|
||||
if (hwr != null)
|
||||
{
|
||||
if (hwr.StatusCode == HttpStatusCode.NotFound)
|
||||
return deserial;
|
||||
if (hwr.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
m_log.Error(string.Format(
|
||||
"[SynchronousRestObjectRequester]: Web request {0} requires authentication ",
|
||||
requestUrl));
|
||||
return deserial;
|
||||
}
|
||||
}
|
||||
else
|
||||
m_log.Error(string.Format(
|
||||
"[SynchronousRestObjectRequester]: WebException for {0} {1} {2} ",
|
||||
|
||||
Reference in New Issue
Block a user