mirror of
https://github.com/opensim/opensim.git
synced 2026-05-15 11:25:39 +08:00
let llgethttpheaders do case insensitive search, plus cosmetics
This commit is contained in:
@@ -450,12 +450,12 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
|
||||
|
||||
public void StopHttpRequest(uint localID, UUID m_itemID)
|
||||
{
|
||||
List<UUID> toremove = new List<UUID>();
|
||||
List<UUID> toremove = new();
|
||||
lock (m_mainLock)
|
||||
{
|
||||
foreach (HttpRequestClass tmpReq in m_pendingRequests.Values)
|
||||
{
|
||||
if(tmpReq.ItemID == m_itemID)
|
||||
if(m_itemID.Equals(tmpReq.ItemID))
|
||||
{
|
||||
tmpReq.Stop();
|
||||
toremove.Add(tmpReq.ReqID);
|
||||
@@ -467,7 +467,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
|
||||
if (m_RequestsThrottle.TryGetValue(localID, out ThrottleData th))
|
||||
{
|
||||
if (th.control + m_primOwnerPerSec * (Util.GetTimeStamp() - th.lastTime) >= m_primBurst)
|
||||
m_RequestsThrottle.TryRemove(localID, out ThrottleData dummy);
|
||||
m_RequestsThrottle.TryRemove(localID, out _);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,9 +85,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
protected readonly Dictionary<UUID, UrlData> m_RequestMap = new Dictionary<UUID, UrlData>();
|
||||
protected readonly Dictionary<string, UrlData> m_UrlMap = new Dictionary<string, UrlData>();
|
||||
protected readonly Dictionary<UUID, int> m_countsPerSOG = new Dictionary<UUID, int>();
|
||||
protected readonly Dictionary<UUID, UrlData> m_RequestMap = new();
|
||||
protected readonly Dictionary<string, UrlData> m_UrlMap = new();
|
||||
protected readonly Dictionary<UUID, int> m_countsPerSOG = new();
|
||||
|
||||
protected bool m_enabled = false;
|
||||
protected string m_ErrorStr;
|
||||
@@ -151,8 +151,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
return;
|
||||
}
|
||||
|
||||
IPAddress ia = null;
|
||||
ia = Util.GetHostFromDNS(ExternalHostNameForLSL);
|
||||
IPAddress ia = Util.GetHostFromDNS(ExternalHostNameForLSL);
|
||||
if (ia == null)
|
||||
{
|
||||
m_ErrorStr = "Could not resolve ExternalHostNameForLSL, HTTP listener for LSL disabled";
|
||||
@@ -245,7 +244,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
string url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString();
|
||||
|
||||
UUID groupID = host.ParentGroup.UUID;
|
||||
UrlData urlData = new UrlData()
|
||||
UrlData urlData = new()
|
||||
{
|
||||
hostID = host.UUID,
|
||||
groupID = groupID,
|
||||
@@ -273,7 +272,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
string uri = "/lslhttp/" + urlcode.ToString();
|
||||
|
||||
PollServiceEventArgs args
|
||||
= new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, Drop, urlcode, 25000);
|
||||
= new(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, Drop, urlcode, 25000);
|
||||
|
||||
m_HttpServer.AddPollServiceHTTPHandlerVarPath(args);
|
||||
|
||||
@@ -314,7 +313,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
string url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString();
|
||||
|
||||
UUID groupID = host.ParentGroup.UUID;
|
||||
UrlData urlData = new UrlData()
|
||||
UrlData urlData = new()
|
||||
{
|
||||
hostID = host.UUID,
|
||||
groupID = groupID,
|
||||
@@ -341,8 +340,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
|
||||
string uri = "/lslhttps/" + urlcode.ToString();
|
||||
|
||||
PollServiceEventArgs args
|
||||
= new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, Drop, urlcode, 25000);
|
||||
PollServiceEventArgs args = new(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, Drop, urlcode, 25000);
|
||||
m_HttpsServer.AddPollServiceHTTPHandlerVarPath(args);
|
||||
|
||||
//m_log.DebugFormat(
|
||||
@@ -359,9 +357,8 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
{
|
||||
lock (m_UrlMap)
|
||||
{
|
||||
UrlData data;
|
||||
url = url.TrimEnd(new char[]{'/'});
|
||||
if (!m_UrlMap.TryGetValue(url, out data))
|
||||
url = url.TrimEnd(new char[] { '/' });
|
||||
if (!m_UrlMap.TryGetValue(url, out UrlData data))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -385,8 +382,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
{
|
||||
lock (m_UrlMap)
|
||||
{
|
||||
UrlData urlData;
|
||||
if (m_RequestMap.TryGetValue(request, out urlData) && urlData != null)
|
||||
if (m_RequestMap.TryGetValue(request, out UrlData urlData) && urlData != null)
|
||||
{
|
||||
urlData.requests[request].responseType = type;
|
||||
}
|
||||
@@ -401,13 +397,11 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
{
|
||||
lock (m_RequestMap)
|
||||
{
|
||||
UrlData urlData;
|
||||
RequestData rd;
|
||||
if (m_RequestMap.TryGetValue(request, out urlData) && urlData != null)
|
||||
if (m_RequestMap.TryGetValue(request, out UrlData urlData) && urlData != null)
|
||||
{
|
||||
lock(urlData.requests)
|
||||
lock (urlData.requests)
|
||||
{
|
||||
if (urlData.requests.TryGetValue(request, out rd) && rd != null)
|
||||
if (urlData.requests.TryGetValue(request, out RequestData rd) && rd != null)
|
||||
{
|
||||
if (!rd.responseSent)
|
||||
{
|
||||
@@ -415,10 +409,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
|
||||
if (rd.responseType.Equals("text/plain"))
|
||||
{
|
||||
string value;
|
||||
if (rd.headers.TryGetValue("user-agent", out value))
|
||||
if (rd.headers.TryGetValue("user-agent", out string value))
|
||||
{
|
||||
if (value != null && value.IndexOf("MSIE") >= 0)
|
||||
if (value != null && value.Contains("MSIE", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
// wrap the html escaped response if the target client is IE
|
||||
// It ignores "text/plain" if the body is html
|
||||
@@ -447,11 +440,9 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
{
|
||||
lock (m_RequestMap)
|
||||
{
|
||||
UrlData urlData;
|
||||
if (m_RequestMap.TryGetValue(requestId, out urlData) && urlData != null)
|
||||
if (m_RequestMap.TryGetValue(requestId, out UrlData urlData) && urlData != null)
|
||||
{
|
||||
string value;
|
||||
if (urlData.requests[requestId].headers.TryGetValue(header, out value))
|
||||
if (urlData.requests[requestId].headers.TryGetValue(header.ToLowerInvariant(), out string value))
|
||||
return value;
|
||||
}
|
||||
else
|
||||
@@ -474,7 +465,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
|
||||
lock (m_UrlMap)
|
||||
{
|
||||
List<string> removeURLs = new List<string>();
|
||||
List<string> removeURLs = new();
|
||||
|
||||
foreach (KeyValuePair<string, UrlData> url in m_UrlMap)
|
||||
{
|
||||
@@ -499,7 +490,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
{
|
||||
lock (m_UrlMap)
|
||||
{
|
||||
List<string> removeURLs = new List<string>();
|
||||
List<string> removeURLs = new();
|
||||
|
||||
foreach (KeyValuePair<string, UrlData> url in m_UrlMap)
|
||||
{
|
||||
@@ -539,7 +530,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
|
||||
protected Hashtable NoEvents(UUID requestID, UUID sessionID)
|
||||
{
|
||||
Hashtable response = new Hashtable();
|
||||
Hashtable response = new();
|
||||
UrlData url;
|
||||
int startTime = 0;
|
||||
lock (m_RequestMap)
|
||||
@@ -571,8 +562,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
|
||||
protected bool HasEvents(UUID requestID, UUID sessionID)
|
||||
{
|
||||
UrlData url=null;
|
||||
|
||||
UrlData url;
|
||||
lock (m_RequestMap)
|
||||
{
|
||||
if (!m_RequestMap.TryGetValue(requestID, out url))
|
||||
@@ -580,8 +570,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
}
|
||||
lock (url.requests)
|
||||
{
|
||||
RequestData rd;
|
||||
if (!url.requests.TryGetValue(requestID, out rd) || rd == null)
|
||||
if (!url.requests.TryGetValue(requestID, out RequestData rd) || rd == null)
|
||||
return false;
|
||||
|
||||
if (System.Environment.TickCount - rd.startTime > 25000)
|
||||
@@ -632,7 +621,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
}
|
||||
}
|
||||
|
||||
Hashtable response = new Hashtable();
|
||||
Hashtable response = new();
|
||||
|
||||
if (System.Environment.TickCount - requestData.startTime > 25000)
|
||||
{
|
||||
@@ -651,7 +640,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
if (url.allowXss)
|
||||
response["access_control_allow_origin"] = "*";
|
||||
|
||||
Hashtable headers = new Hashtable();
|
||||
Hashtable headers = new();
|
||||
if(url.scene != null)
|
||||
{
|
||||
SceneObjectPart sop = url.scene.GetSceneObjectPart(url.hostID);
|
||||
@@ -684,8 +673,10 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
|
||||
private OSHttpResponse errorResponse(OSHttpRequest request, int error)
|
||||
{
|
||||
OSHttpResponse resp = new OSHttpResponse(request);
|
||||
resp.StatusCode = error;
|
||||
OSHttpResponse resp = new(request)
|
||||
{
|
||||
StatusCode = error
|
||||
};
|
||||
return resp;
|
||||
}
|
||||
|
||||
@@ -710,8 +701,8 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
int pos = uri.IndexOf('/', 45); // /lslhttp/uuid/ <-
|
||||
if (pos >= 45)
|
||||
{
|
||||
uri_tmp = uri.Substring(0, pos);
|
||||
pathInfo = uri.Substring(pos);
|
||||
uri_tmp = uri[..pos];
|
||||
pathInfo = uri[pos..];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -736,7 +727,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
//for llGetHttpHeader support we need to store original URI here
|
||||
//to make x-path-info / x-query-string / x-script-url / x-remote-ip headers
|
||||
//as per http://wiki.secondlife.com/wiki/LlGetHTTPHeader
|
||||
RequestData requestData = new RequestData()
|
||||
RequestData requestData = new()
|
||||
{
|
||||
requestID = requestID,
|
||||
requestDone = false,
|
||||
@@ -746,8 +737,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
scene = url.scene
|
||||
};
|
||||
|
||||
if (requestData.headers == null)
|
||||
requestData.headers = new Dictionary<string, string>();
|
||||
requestData.headers ??= new Dictionary<string, string>();
|
||||
|
||||
NameValueCollection headers = request.Headers;
|
||||
if (headers.Count > 0)
|
||||
@@ -763,7 +753,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
NameValueCollection query = request.QueryString;
|
||||
if (query.Count > 0)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder sb = new();
|
||||
for (int i = 0; i < query.Count; ++i)
|
||||
{
|
||||
string key = query.GetKey(i);
|
||||
@@ -799,7 +789,7 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
|
||||
string requestBody;
|
||||
if (request.InputStream.Length > 0)
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(request.InputStream, Encoding.UTF8))
|
||||
using (StreamReader reader = new(request.InputStream, Encoding.UTF8))
|
||||
requestBody = reader.ReadToEnd();
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user