public UUID StartHttpRequest(uint localID, UUID itemID, string url, List <string> parameters, Dictionary <string, string> headers, string body) { UUID reqID = UUID.Random(); HttpRequestClass htc = new HttpRequestClass(); // Partial implementation: support for parameter flags needed // see http://wiki.secondlife.com/wiki/LlHTTPRequest // // Parameters are expected in {key, value, ... , key, value} if (parameters != null) { string[] parms = parameters.ToArray(); for (int i = 0; i < parms.Length; i += 2) { switch (Int32.Parse(parms[i])) { case (int)HttpRequestConstants.HTTP_METHOD: htc.HttpMethod = parms[i + 1]; break; case (int)HttpRequestConstants.HTTP_MIMETYPE: htc.HttpMIMEType = parms[i + 1]; break; case (int)HttpRequestConstants.HTTP_BODY_MAXLENGTH: // TODO implement me break; case (int)HttpRequestConstants.HTTP_VERIFY_CERT: // TODO implement me break; } } } htc.LocalID = localID; htc.ItemID = itemID; htc.Url = url; htc.ReqID = reqID; htc.HttpTimeout = httpTimeout; htc.OutboundBody = body; htc.ResponseHeaders = headers; htc.proxyurl = m_proxyurl; htc.proxyexcepts = m_proxyexcepts; lock (HttpListLock) { m_pendingRequests.Add(reqID, htc); } htc.Process(); return(reqID); }
public bool StartHttpRequest(HttpRequestClass req) { if (!CheckAllowed(new Uri(req.Url))) { return(false); } lock (HttpListLock) { m_pendingRequests.Add(req.ReqID, req); } req.Process(); return(true); }
public UUID StartHttpRequest(uint localID, UUID itemID, string url, List<string> parameters, Dictionary<string, string> headers, string body) { UUID reqID = UUID.Random(); HttpRequestClass htc = new HttpRequestClass(); // Partial implementation: support for parameter flags needed // see http://wiki.secondlife.com/wiki/LlHTTPRequest // // Parameters are expected in {key, value, ... , key, value} if (parameters != null) { string[] parms = parameters.ToArray(); for (int i = 0; i < parms.Length; i += 2) { switch (Int32.Parse(parms[i])) { case (int)HttpRequestConstants.HTTP_METHOD: htc.HttpMethod = parms[i + 1]; break; case (int)HttpRequestConstants.HTTP_MIMETYPE: htc.HttpMIMEType = parms[i + 1]; break; case (int)HttpRequestConstants.HTTP_BODY_MAXLENGTH: // TODO implement me break; case (int)HttpRequestConstants.HTTP_VERIFY_CERT: // TODO implement me break; } } } htc.LocalID = localID; htc.ItemID = itemID; htc.Url = url; htc.ReqID = reqID; htc.HttpTimeout = httpTimeout; htc.OutboundBody = body; htc.ResponseHeaders = headers; htc.proxyurl = m_proxyurl; htc.proxyexcepts = m_proxyexcepts; lock (HttpListLock) { m_pendingRequests.Add(reqID, htc); } htc.Process(); return reqID; }
public UUID StartHttpRequest(UUID primID, UUID itemID, string url, List<string> parameters, Dictionary<string, string> headers, string body) { UUID reqID = UUID.Random(); HttpRequestClass htc = new HttpRequestClass(); // Partial implementation: support for parameter flags needed // see http://wiki.secondlife.com/wiki/LlHTTPRequest // // Parameters are expected in {key, value, ... , key, value} int BODY_MAXLENGTH = DEFAULT_BODY_MAXLENGTH; if (parameters != null) { string[] parms = parameters.ToArray(); for (int i = 0; i < parms.Length; i += 2) { switch (Int32.Parse(parms[i])) { case (int) HttpRequestConstants.HTTP_METHOD: htc.HttpMethod = parms[i + 1]; break; case (int) HttpRequestConstants.HTTP_MIMETYPE: htc.HttpMIMEType = parms[i + 1]; break; case (int) HttpRequestConstants.HTTP_BODY_MAXLENGTH: BODY_MAXLENGTH = int.Parse(parms[i + 1]); break; case (int) HttpRequestConstants.HTTP_VERIFY_CERT: htc.HttpVerifyCert = (int.Parse(parms[i + 1]) != 0); break; } } } bool ShouldProcess = true; HTTPMax r = null; if (!m_numberOfPrimHTTPRequests.TryGetValue(primID, out r)) r = new HTTPMax(); if (DateTime.Now.AddSeconds(1).Ticks > r.LastTicks) r.Number = 0; if (r.Number++ > MaxNumberOfHTTPRequestsPerSecond) { ShouldProcess = false; //Too many for this prim, return status 499 htc.Status = (int) OSHttpStatusCode.ClientErrorJoker; htc.Finished = true; } htc.PrimID = primID; htc.ItemID = itemID; htc.Url = url; htc.MaxLength = BODY_MAXLENGTH; htc.ReqID = reqID; htc.HttpTimeout = httpTimeout; htc.OutboundBody = body; htc.ResponseHeaders = headers; htc.proxyurl = m_proxyurl; htc.proxyexcepts = m_proxyexcepts; lock (HttpListLock) { if (m_pendingRequests.ContainsKey(itemID)) m_pendingRequests[itemID].Add(htc); else { m_reqID2itemID.Add(reqID, itemID); m_pendingRequests.Add(itemID, new List<HttpRequestClass> {htc}); } } if (ShouldProcess) htc.Process(); //Make sure that the cmd handler thread is running m_scriptModule.PokeThreads(itemID); return reqID; }
public UUID StartHttpRequest(uint localID, UUID itemID, string url, List <string> parameters, Dictionary <string, string> headers, string body) { UUID reqID = UUID.Random(); HttpRequestClass htc = new HttpRequestClass(); // Partial implementation: support for parameter flags needed // see http://wiki.secondlife.com/wiki/LlHTTPRequest // // Parameters are expected in {key, value, ... , key, value} if (parameters != null) { string[] parms = parameters.ToArray(); for (int i = 0; i < parms.Length; i += 2) { switch (Int32.Parse(parms[i])) { case (int)HttpRequestConstants.HTTP_METHOD: htc.HttpMethod = parms[i + 1]; break; case (int)HttpRequestConstants.HTTP_MIMETYPE: htc.HttpMIMEType = parms[i + 1]; break; case (int)HttpRequestConstants.HTTP_BODY_MAXLENGTH: // TODO implement me break; case (int)HttpRequestConstants.HTTP_VERIFY_CERT: htc.HttpVerifyCert = (int.Parse(parms[i + 1]) != 0); break; case (int)HttpRequestConstants.HTTP_VERBOSE_THROTTLE: // TODO implement me break; case (int)HttpRequestConstants.HTTP_CUSTOM_HEADER: //Parameters are in pairs and custom header takes //arguments in pairs so adjust for header marker. ++i; //Maximum of 8 headers are allowed based on the //Second Life documentation for llHTTPRequest. for (int count = 1; count <= 8; ++count) { //Not enough parameters remaining for a header? if (parms.Length - i < 2) { break; } //Have we reached the end of the list of headers? //End is marked by a string with a single digit. //We already know we have at least one parameter //so it is safe to do this check at top of loop. if (Char.IsDigit(parms[i][0])) { break; } if (htc.HttpCustomHeaders == null) { htc.HttpCustomHeaders = new List <string>(); } htc.HttpCustomHeaders.Add(parms[i]); htc.HttpCustomHeaders.Add(parms[i + 1]); i += 2; } break; case (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE: htc.HttpPragmaNoCache = (int.Parse(parms[i + 1]) != 0); break; } } } htc.LocalID = localID; htc.ItemID = itemID; htc.Url = url; htc.ReqID = reqID; htc.HttpTimeout = httpTimeout; htc.OutboundBody = body; htc.ResponseHeaders = headers; htc.proxyurl = m_proxyurl; htc.proxyexcepts = m_proxyexcepts; m_pendingRequests.Add(reqID, htc); htc.Process(); return(reqID); }
public UUID StartHttpRequest( uint localID, UUID itemID, string url, List <string> parameters, Dictionary <string, string> headers, string body, out HttpInitialRequestStatus status) { if (!CheckAllowed(new Uri(url))) { status = HttpInitialRequestStatus.DISALLOWED_BY_FILTER; return(UUID.Zero); } UUID reqID = UUID.Random(); HttpRequestClass htc = new HttpRequestClass(); // Partial implementation: support for parameter flags needed // see http://wiki.secondlife.com/wiki/LlHTTPRequest // // Parameters are expected in {key, value, ... , key, value} if (parameters != null) { string[] parms = parameters.ToArray(); for (int i = 0; i < parms.Length; i += 2) { switch (Int32.Parse(parms[i])) { case (int)HttpRequestConstants.HTTP_METHOD: htc.HttpMethod = parms[i + 1]; break; case (int)HttpRequestConstants.HTTP_MIMETYPE: htc.HttpMIMEType = parms[i + 1]; break; case (int)HttpRequestConstants.HTTP_BODY_MAXLENGTH: int len; if (int.TryParse(parms[i + 1], out len)) { if (len > HttpRequestClass.HttpBodyMaxLenMAX) { len = HttpRequestClass.HttpBodyMaxLenMAX; } else if (len < 64) //??? { len = 64; } htc.HttpBodyMaxLen = len; } break; case (int)HttpRequestConstants.HTTP_VERIFY_CERT: htc.HttpVerifyCert = (int.Parse(parms[i + 1]) != 0); break; case (int)HttpRequestConstants.HTTP_VERBOSE_THROTTLE: // TODO implement me break; case (int)HttpRequestConstants.HTTP_CUSTOM_HEADER: //Parameters are in pairs and custom header takes //arguments in pairs so adjust for header marker. ++i; //Maximum of 8 headers are allowed based on the //Second Life documentation for llHTTPRequest. for (int count = 1; count <= 8; ++count) { //Not enough parameters remaining for a header? if (parms.Length - i < 2) { break; } if (htc.HttpCustomHeaders == null) { htc.HttpCustomHeaders = new List <string>(); } htc.HttpCustomHeaders.Add(parms[i]); htc.HttpCustomHeaders.Add(parms[i + 1]); int nexti = i + 2; if (nexti >= parms.Length || Char.IsDigit(parms[nexti][0])) { break; } i = nexti; } break; case (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE: htc.HttpPragmaNoCache = (int.Parse(parms[i + 1]) != 0); break; } } } htc.RequestModule = this; htc.LocalID = localID; htc.ItemID = itemID; htc.Url = url; htc.ReqID = reqID; htc.HttpTimeout = m_httpTimeout; htc.OutboundBody = body; htc.ResponseHeaders = headers; htc.proxyurl = m_proxyurl; htc.proxyexcepts = m_proxyexcepts; // Same number as default HttpWebRequest.MaximumAutomaticRedirections htc.MaxRedirects = 50; lock (m_mainLock) m_pendingRequests.Add(reqID, htc); htc.Process(); status = HttpInitialRequestStatus.OK; return(reqID); }
public UUID StartHttpRequest(uint localID, UUID itemID, string url, List<string> parameters, Dictionary<string, string> headers, string body) { UUID reqID = UUID.Random(); HttpRequestClass htc = new HttpRequestClass(); // Partial implementation: support for parameter flags needed // see http://wiki.secondlife.com/wiki/LlHTTPRequest // // Parameters are expected in {key, value, ... , key, value} if (parameters != null) { string[] parms = parameters.ToArray(); for (int i = 0; i < parms.Length; i += 2) { switch (Int32.Parse(parms[i])) { case (int)HttpRequestConstants.HTTP_METHOD: htc.HttpMethod = parms[i + 1]; break; case (int)HttpRequestConstants.HTTP_MIMETYPE: htc.HttpMIMEType = parms[i + 1]; break; case (int)HttpRequestConstants.HTTP_BODY_MAXLENGTH: // TODO implement me break; case (int)HttpRequestConstants.HTTP_VERIFY_CERT: htc.HttpVerifyCert = (int.Parse(parms[i + 1]) != 0); break; case (int)HttpRequestConstants.HTTP_VERBOSE_THROTTLE: // TODO implement me break; case (int)HttpRequestConstants.HTTP_CUSTOM_HEADER: //Parameters are in pairs and custom header takes //arguments in pairs so adjust for header marker. ++i; //Maximum of 8 headers are allowed based on the //Second Life documentation for llHTTPRequest. for (int count = 1; count <= 8; ++count) { //Not enough parameters remaining for a header? if (parms.Length - i < 2) break; //Have we reached the end of the list of headers? //End is marked by a string with a single digit. //We already know we have at least one parameter //so it is safe to do this check at top of loop. if (Char.IsDigit(parms[i][0])) break; if (htc.HttpCustomHeaders == null) htc.HttpCustomHeaders = new List<string>(); htc.HttpCustomHeaders.Add(parms[i]); htc.HttpCustomHeaders.Add(parms[i+1]); i += 2; } break; case (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE: htc.HttpPragmaNoCache = (int.Parse(parms[i + 1]) != 0); break; } } } htc.LocalID = localID; htc.ItemID = itemID; htc.Url = url; htc.ReqID = reqID; htc.HttpTimeout = httpTimeout; htc.OutboundBody = body; htc.ResponseHeaders = headers; htc.proxyurl = m_proxyurl; htc.proxyexcepts = m_proxyexcepts; lock (HttpListLock) { m_pendingRequests.Add(reqID, htc); } htc.Process(); return reqID; }
public bool StartHttpRequest(HttpRequestClass req) { if (!CheckAllowed(new Uri(req.Url))) return false; lock (HttpListLock) { m_pendingRequests.Add(req.ReqID, req); } req.Process(); return true; }
public UUID StartHttpRequest(UUID primID, UUID itemID, string url, List <string> parameters, Dictionary <string, string> headers, string body) { UUID reqID = UUID.Random(); HttpRequestClass htc = new HttpRequestClass(); // Partial implementation: support for parameter flags needed // see http://wiki.secondlife.com/wiki/LlHTTPRequest // // Parameters are expected in {key, value, ... , key, value} int BODY_MAXLENGTH = DEFAULT_BODY_MAXLENGTH; if (parameters != null) { string[] parms = parameters.ToArray(); for (int i = 0; i < parms.Length; i += 2) { switch (Int32.Parse(parms[i])) { case (int)HttpRequestConstants.HTTP_METHOD: htc.HttpMethod = parms[i + 1]; break; case (int)HttpRequestConstants.HTTP_MIMETYPE: htc.HttpMIMEType = parms[i + 1]; break; case (int)HttpRequestConstants.HTTP_BODY_MAXLENGTH: BODY_MAXLENGTH = int.Parse(parms[i + 1]); break; case (int)HttpRequestConstants.HTTP_VERIFY_CERT: htc.HttpVerifyCert = (int.Parse(parms[i + 1]) != 0); break; } } } bool ShouldProcess = true; HTTPMax r = null; if (!m_numberOfPrimHTTPRequests.TryGetValue(primID, out r)) { r = new HTTPMax(); } if (DateTime.Now.AddSeconds(1).Ticks > r.LastTicks) { r.Number = 0; } if (r.Number++ > MaxNumberOfHTTPRequestsPerSecond) { ShouldProcess = false; //Too many for this prim, return status 499 htc.Status = (int)OSHttpStatusCode.ClientErrorJoker; htc.Finished = true; } htc.PrimID = primID; htc.ItemID = itemID; htc.Url = url; htc.MaxLength = BODY_MAXLENGTH; htc.ReqID = reqID; htc.HttpTimeout = httpTimeout; htc.OutboundBody = body; htc.ResponseHeaders = headers; htc.proxyurl = m_proxyurl; htc.proxyexcepts = m_proxyexcepts; lock (HttpListLock) { if (m_pendingRequests.ContainsKey(itemID)) { m_pendingRequests[itemID].Add(htc); } else { m_reqID2itemID.Add(reqID, itemID); m_pendingRequests.Add(itemID, new List <HttpRequestClass>() { htc }); } } if (ShouldProcess) { htc.Process(); } //Make sure that the cmd handler thread is running m_scriptModule.PokeThreads(); return(reqID); }