mirror of
https://github.com/opensim/opensim.git
synced 2026-08-04 16:22:50 +08:00
allow setting of MaxResponseContentBufferSize per instance ofglobal httpclient; limit it to 1MB on webrtc
This commit is contained in:
@@ -94,7 +94,7 @@ namespace osWebRtcVoice
|
||||
AttachPluginResp handleResp = new(resp);
|
||||
PluginId = handleResp.pluginId;
|
||||
PluginUri = _JanusSession.SessionUri + "/" + PluginId;
|
||||
m_log.DebugFormat("{0} Activate. Plugin attached. ID={1}, URL={2}", LogHeader, PluginId, PluginUri);
|
||||
m_log.Debug($"{LogHeader} Activate. Plugin attached. ID={PluginId}, URL={PluginUri}");
|
||||
_JanusSession.PluginId = PluginId;
|
||||
_JanusSession.OnEvent += Handle_Event;
|
||||
_JanusSession.OnMessage += Handle_Message;
|
||||
@@ -102,12 +102,12 @@ namespace osWebRtcVoice
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.ErrorFormat("{0} Activate: failed to attach to plugin {1}", LogHeader, PluginName);
|
||||
m_log.Error($"{LogHeader} Activate: failed to attach to plugin {PluginName}");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.ErrorFormat("{0} Activate: exception attaching to plugin {1}: {2}", LogHeader, PluginName, e);
|
||||
m_log.Error($"{LogHeader} Activate: exception attaching to plugin {PluginName}:", e);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -118,7 +118,7 @@ namespace osWebRtcVoice
|
||||
bool ret = false;
|
||||
if (!IsConnected || _JanusSession is null)
|
||||
{
|
||||
m_log.WarnFormat("{0} Detach. Not connected", LogHeader);
|
||||
m_log.Warn($"{LogHeader} Detach. Not connected");
|
||||
return ret;
|
||||
}
|
||||
try
|
||||
@@ -129,17 +129,17 @@ namespace osWebRtcVoice
|
||||
JanusMessageResp resp = await _JanusSession.SendToJanus(new DetachPluginReq(), PluginUri).ConfigureAwait(false);
|
||||
if (resp is not null && resp.isSuccess)
|
||||
{
|
||||
m_log.DebugFormat("{0} Detach. Detached", LogHeader);
|
||||
m_log.Debug($"{LogHeader} Detach. Detached");
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.ErrorFormat("{0} Detach: failed", LogHeader);
|
||||
m_log.Error($"{LogHeader} Detach: failed");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.ErrorFormat("{0} Detach: exception {1}", LogHeader, e);
|
||||
m_log.Error($"{LogHeader} Detach: exception", e);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -147,11 +147,11 @@ namespace osWebRtcVoice
|
||||
|
||||
public virtual void Handle_Event(JanusMessageResp pResp)
|
||||
{
|
||||
m_log.DebugFormat("{0} Handle_Event: {1}", LogHeader, pResp.ToString());
|
||||
m_log.Debug($"{LogHeader} Handle_Event: {pResp}");
|
||||
}
|
||||
public virtual void Handle_Message(JanusMessageResp pResp)
|
||||
{
|
||||
m_log.DebugFormat("{0} Handle_Message: {1}", LogHeader, pResp.ToString());
|
||||
m_log.Debug($"{LogHeader} Handle_Message: {pResp}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -266,7 +266,6 @@ namespace osWebRtcVoice
|
||||
{
|
||||
AddJanusHeaders(pReq, admin);
|
||||
if (_MessageDetails) m_log.DebugFormat($"{LogHeader} SendToJanus. URI={pURI}, req={pReq.ToJson}");
|
||||
// if (_MessageDetails) DebugLog("{0} SendToJanus. URI={1}, req={2}", LogHeader, pURI, pReq.ToJson());
|
||||
|
||||
JanusMessageResp ret = null;
|
||||
try
|
||||
@@ -285,7 +284,7 @@ namespace osWebRtcVoice
|
||||
HttpRequestMessage reqMsg = new(HttpMethod.Post, pURI);
|
||||
reqMsg.Content = new StringContent(reqStr, System.Text.Encoding.UTF8, MediaTypeNames.Application.Json);
|
||||
reqMsg.Headers.TryAddWithoutValidation("Accept", "application/json");
|
||||
// HttpResponseMessage response = await httpClient.SendAsync(reqMsg, _CancelTokenSource.Token);
|
||||
|
||||
HttpResponseMessage response = await httpClient.SendAsync(reqMsg).ConfigureAwait(false);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
@@ -321,7 +320,7 @@ namespace osWebRtcVoice
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Error("{LogHeader} SendToJanus: response not successful {response}");
|
||||
m_log.Error($"{LogHeader} SendToJanus: response not successful {response}");
|
||||
_= _OutstandingRequests.TryRemove(pReq.TransactionId, out _);
|
||||
}
|
||||
}
|
||||
@@ -452,13 +451,12 @@ namespace osWebRtcVoice
|
||||
{
|
||||
// m_log.DebugFormat("{0} GetFromJanus: URI = \"{1}\"", LogHeader, pURI);
|
||||
//HttpClient httpClient = WebUtil.GetNewGlobalHttpClient(timeout);
|
||||
HttpClient httpClient = WebUtil.GetGlobalNoRedirHttpClient(timeout);
|
||||
HttpClient httpClient = WebUtil.GetGlobalNoRedirHttpClient(timeout, 1024 * 1024);
|
||||
HttpRequestMessage reqMsg = new HttpRequestMessage(HttpMethod.Get, pURI);
|
||||
reqMsg.Headers.TryAddWithoutValidation("Accept", "application/json");
|
||||
HttpResponseMessage response = null;
|
||||
try
|
||||
{
|
||||
// response = await httpClient.SendAsync(reqMsg, _CancelTokenSource.Token);
|
||||
response = await httpClient.SendAsync(reqMsg).ConfigureAwait(false);
|
||||
|
||||
if (response is not null && response.IsSuccessStatusCode)
|
||||
@@ -469,28 +467,26 @@ namespace osWebRtcVoice
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Error($"{LogHeader} GetFromJanus: response not successful {response}");
|
||||
// m_log.ErrorFormat("{0} GetFromJanus: response not successful", LogHeader);
|
||||
// if (m_log.IsDebugEnabled)
|
||||
// m_log.DebugFormat("{0} GetFromJanus: response detail {1}", LogHeader, response);
|
||||
ErrorResp eResp = new("GETERROR");
|
||||
// Add the sessionId so the proper session can be shut down
|
||||
eResp.AddSessionId(SessionId);
|
||||
if (response is not null)
|
||||
{
|
||||
eResp.SetError((int)response.StatusCode, response.ReasonPhrase);
|
||||
m_log.Error($"{LogHeader} GetFromJanus: response not successful {response}");
|
||||
}
|
||||
else
|
||||
{
|
||||
eResp.SetError(0, "Connection refused");
|
||||
m_log.Error($"{LogHeader} GetFromJanus: response not successful");
|
||||
}
|
||||
ret = eResp;
|
||||
}
|
||||
}
|
||||
catch (TaskCanceledException e)
|
||||
{
|
||||
if (_MessageDetails) m_log.DebugFormat("{0} GetFromJanus: task canceled: {1}", LogHeader, e.Message);
|
||||
// if (_MessageDetails) DebugLog("{0} GetFromJanus: task canceled: {1}", LogHeader, e.Message);
|
||||
if (_MessageDetails)
|
||||
m_log.Debug($"{LogHeader} GetFromJanus: task canceled: {e.Message}");
|
||||
|
||||
ErrorResp eResp = new("GETERROR");
|
||||
eResp.SetError(499, "Task canceled");
|
||||
@@ -498,7 +494,7 @@ namespace osWebRtcVoice
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.ErrorFormat("{0} GetFromJanus: exception {1}", LogHeader, e.Message);
|
||||
m_log.Error($"{LogHeader} GetFromJanus: exception {e.Message}");
|
||||
ErrorResp eResp = new("GETERROR");
|
||||
eResp.SetError(400, "Exception: " + e.Message);
|
||||
ret = eResp;
|
||||
@@ -506,7 +502,7 @@ namespace osWebRtcVoice
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.ErrorFormat("{0} GetFromJanus: exception {1}", LogHeader, e);
|
||||
m_log.Error($"{LogHeader} GetFromJanus: exception ", e);
|
||||
ErrorResp eResp = new("GETERROR");
|
||||
eResp.SetError(400, "Exception: " + e.Message);
|
||||
ret = eResp;
|
||||
|
||||
@@ -205,7 +205,7 @@ namespace osWebRtcVoice
|
||||
|
||||
if(request.HttpMethod != "POST")
|
||||
{
|
||||
m_log.Debug($"[{logHeader}][ProvisionVoice]: Not a POST request. Agent={agentID}");
|
||||
m_log.Debug($"{logHeader}[ProvisionVoice]: Not a POST request. Agent={agentID}");
|
||||
response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||
return;
|
||||
}
|
||||
@@ -343,7 +343,7 @@ namespace osWebRtcVoice
|
||||
|
||||
if(request.HttpMethod != "POST")
|
||||
{
|
||||
m_log.Error($"[{logHeader}][VoiceSignaling]: Not a POST request. Agent={agentID}");
|
||||
m_log.Error($"{logHeader}[VoiceSignaling]: Not a POST request. Agent={agentID}");
|
||||
response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -244,23 +244,23 @@ namespace OpenSim.Framework
|
||||
SharedSocketsHttpHandler = shh;
|
||||
}
|
||||
|
||||
public static HttpClient GetNewGlobalHttpClient(int timeout)
|
||||
public static HttpClient GetNewGlobalHttpClient(int timeout, int maxBufferSize = 250 * 1024 * 1024)
|
||||
{
|
||||
var client = new HttpClient(SharedSocketsHttpHandler, false)
|
||||
{
|
||||
Timeout = TimeSpan.FromMilliseconds(timeout > 0 ? timeout : 30000),
|
||||
MaxResponseContentBufferSize = 250 * 1024 * 1024,
|
||||
MaxResponseContentBufferSize = maxBufferSize,
|
||||
};
|
||||
client.DefaultRequestHeaders.ExpectContinue = false;
|
||||
return client;
|
||||
}
|
||||
|
||||
public static HttpClient GetGlobalNoRedirHttpClient(int timeout)
|
||||
public static HttpClient GetGlobalNoRedirHttpClient(int timeout, int maxBufferSize = 250 * 1024 * 1024)
|
||||
{
|
||||
var client = new HttpClient(SharedSocketsHttpHandlerNoRedir, false)
|
||||
{
|
||||
Timeout = TimeSpan.FromMilliseconds(timeout > 0 ? timeout : 30000),
|
||||
MaxResponseContentBufferSize = 250 * 1024 * 1024,
|
||||
MaxResponseContentBufferSize = maxBufferSize,
|
||||
};
|
||||
client.DefaultRequestHeaders.ExpectContinue = false;
|
||||
return client;
|
||||
|
||||
Reference in New Issue
Block a user