public override byte[] Handle(string path, Stream request,
OSHttpRequest httpRequest, OSHttpResponse httpResponse)
{
MainConsole.Instance.DebugFormat ("[SIMULATION]: Stream handler called");
Hashtable keysvals = new Hashtable ();
Hashtable headervals = new Hashtable ();
string[] querystringkeys = httpRequest.QueryString.AllKeys;
string[] rHeaders = httpRequest.Headers.AllKeys;
keysvals.Add ("uri", httpRequest.RawUrl);
keysvals.Add ("content-type", httpRequest.ContentType);
keysvals.Add ("http-method", httpRequest.HttpMethod);
foreach (string queryname in querystringkeys)
keysvals.Add (queryname, httpRequest.QueryString[queryname]);
foreach (string headername in rHeaders)
headervals[headername] = httpRequest.Headers[headername];
keysvals.Add ("headers", headervals);
keysvals.Add ("querystringkeys", querystringkeys);
Stream inputStream;
if (httpRequest.ContentType == "application/x-gzip")
inputStream = new GZipStream (request, CompressionMode.Decompress);
else
inputStream = request;
Encoding encoding = Encoding.UTF8;
StreamReader reader = new StreamReader (inputStream, encoding);
string requestBody = reader.ReadToEnd ();
reader.Close ();
keysvals.Add ("body", requestBody);
httpResponse.StatusCode = 200;
httpResponse.ContentType = "text/html";
httpResponse.KeepAlive = false;
Hashtable responsedata = new Hashtable ();
UUID agentID;
UUID regionID;
string action;
if (!WebUtils.GetParams ((string)keysvals["uri"], out agentID, out regionID, out action))
{
MainConsole.Instance.InfoFormat ("[AGENT HANDLER]: Invalid parameters for agent message {0}", keysvals["uri"]);
httpResponse.StatusCode = 404;
return encoding.GetBytes ("false");
}
DoAgentPost (keysvals, responsedata, agentID);
httpResponse.StatusCode = (int)responsedata["int_response_code"];
return encoding.GetBytes ((string)responsedata["str_response_string"]);
}