Revert "Refactor scripted http request to use async calls rather than hard threads"
This reverts commit 461ecd7cf9
.
avinationmerge
parent
461ecd7cf9
commit
cf4bf7432a
|
@ -206,7 +206,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
|
|||
m_pendingRequests.Add(reqID, htc);
|
||||
}
|
||||
|
||||
htc.SendRequest();
|
||||
htc.Process();
|
||||
|
||||
return reqID;
|
||||
}
|
||||
|
@ -340,6 +340,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
|
|||
public string HttpMIMEType = "text/plain;charset=utf-8";
|
||||
public int HttpTimeout;
|
||||
public bool HttpVerifyCert = true;
|
||||
private Thread httpThread;
|
||||
|
||||
// Request info
|
||||
private UUID _itemID;
|
||||
|
@ -373,11 +374,27 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
|
|||
|
||||
public void Process()
|
||||
{
|
||||
SendRequest();
|
||||
httpThread = new Thread(SendRequest);
|
||||
httpThread.Name = "HttpRequestThread";
|
||||
httpThread.Priority = ThreadPriority.BelowNormal;
|
||||
httpThread.IsBackground = true;
|
||||
_finished = false;
|
||||
httpThread.Start();
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: More work on the response codes. Right now
|
||||
* returning 200 for success or 499 for exception
|
||||
*/
|
||||
|
||||
public void SendRequest()
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
byte[] buf = new byte[8192];
|
||||
string tempString = null;
|
||||
int count = 0;
|
||||
|
||||
try
|
||||
{
|
||||
Request = (HttpWebRequest) WebRequest.Create(Url);
|
||||
|
@ -392,9 +409,13 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
|
|||
{
|
||||
// We could hijack Connection Group Name to identify
|
||||
// a desired security exception. But at the moment we'll use a dummy header instead.
|
||||
// Request.ConnectionGroupName = "NoVerify";
|
||||
Request.Headers.Add("NoVerifyCert", "true");
|
||||
}
|
||||
|
||||
// else
|
||||
// {
|
||||
// Request.ConnectionGroupName="Verify";
|
||||
// }
|
||||
if (proxyurl != null && proxyurl.Length > 0)
|
||||
{
|
||||
if (proxyexcepts != null && proxyexcepts.Length > 0)
|
||||
|
@ -409,14 +430,10 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
|
|||
}
|
||||
|
||||
foreach (KeyValuePair<string, string> entry in ResponseHeaders)
|
||||
{
|
||||
if (entry.Key.ToLower().Equals("user-agent"))
|
||||
Request.UserAgent = entry.Value;
|
||||
else
|
||||
Request.Headers[entry.Key] = entry.Value;
|
||||
}
|
||||
|
||||
Request.Timeout = HttpTimeout;
|
||||
|
||||
// Encode outbound data
|
||||
if (OutboundBody.Length > 0)
|
||||
|
@ -424,78 +441,16 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
|
|||
byte[] data = Util.UTF8.GetBytes(OutboundBody);
|
||||
|
||||
Request.ContentLength = data.Length;
|
||||
Request.BeginGetRequestStream(new AsyncCallback(SendRequestData), this);
|
||||
return;
|
||||
Stream bstream = Request.GetRequestStream();
|
||||
bstream.Write(data, 0, data.Length);
|
||||
bstream.Close();
|
||||
}
|
||||
|
||||
Request.BeginGetResponse(new AsyncCallback(ProcessResponse), this);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Do nothing. Abort was called.
|
||||
}
|
||||
}
|
||||
|
||||
private void SendRequestData(IAsyncResult ar)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] data = Util.UTF8.GetBytes(OutboundBody);
|
||||
|
||||
Stream bstream = Request.EndGetRequestStream(ar);
|
||||
bstream.Write(data, 0, data.Length);
|
||||
bstream.Close();
|
||||
|
||||
Request.BeginGetResponse(new AsyncCallback(ProcessResponse), this);
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
// Abort was called. Just go away
|
||||
if (e.Status == WebExceptionStatus.RequestCanceled)
|
||||
return;
|
||||
|
||||
// Server errored on request
|
||||
if (e.Status == WebExceptionStatus.ProtocolError && e.Response != null)
|
||||
{
|
||||
HttpWebResponse webRsp = (HttpWebResponse)e.Response;
|
||||
|
||||
Status = (int)webRsp.StatusCode;
|
||||
|
||||
try
|
||||
{
|
||||
using (Stream responseStream = webRsp.GetResponseStream())
|
||||
{
|
||||
ResponseBody = responseStream.GetStreamString();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
ResponseBody = webRsp.StatusDescription;
|
||||
}
|
||||
finally
|
||||
{
|
||||
webRsp.Close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
_finished = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessResponse(IAsyncResult ar)
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
byte[] buf = new byte[8192];
|
||||
string tempString = null;
|
||||
int count = 0;
|
||||
|
||||
try
|
||||
{
|
||||
Request.Timeout = HttpTimeout;
|
||||
try
|
||||
{
|
||||
response = (HttpWebResponse) Request.EndGetResponse(ar);
|
||||
// execute the request
|
||||
response = (HttpWebResponse) Request.GetResponse();
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
|
@ -530,21 +485,32 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
|
|||
|
||||
ResponseBody = sb.ToString().Replace("\r", "");
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
// Abort was called. Just go away
|
||||
if (e.Status == WebExceptionStatus.RequestCanceled)
|
||||
return;
|
||||
|
||||
Status = (int)OSHttpStatusCode.ClientErrorJoker;
|
||||
|
||||
ResponseBody = e.Message;
|
||||
_finished = true;
|
||||
return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Ignore
|
||||
if (e is WebException && ((WebException)e).Status == WebExceptionStatus.ProtocolError)
|
||||
{
|
||||
HttpWebResponse webRsp = (HttpWebResponse)((WebException)e).Response;
|
||||
Status = (int)webRsp.StatusCode;
|
||||
try
|
||||
{
|
||||
using (Stream responseStream = webRsp.GetResponseStream())
|
||||
{
|
||||
ResponseBody = responseStream.GetStreamString();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
ResponseBody = webRsp.StatusDescription;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = (int)OSHttpStatusCode.ClientErrorJoker;
|
||||
ResponseBody = e.Message;
|
||||
}
|
||||
|
||||
_finished = true;
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -559,7 +525,7 @@ namespace OpenSim.Region.CoreModules.Scripting.HttpRequest
|
|||
{
|
||||
try
|
||||
{
|
||||
Request.Abort();
|
||||
httpThread.Abort();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue