Наследование: IServiceRequest
        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;
        }
        /// <summary>
        /// Test what happens when we get a 404 response from a call.
        /// </summary>
//        [Test]
        public void Test404Response()
        {
            TestHelpers.InMethod();
            TestHelpers.EnableLogging();

            if (!Util.IsPlatformMono)
                Assert.Ignore("Ignoring test since can only currently run on Mono");           

            string rawResponse = "boom";

            TestWebRequestCreate twrc = new TestWebRequestCreate();

            TestWebRequest twr = new TestWebRequest();
            //twr.OnEndGetResponse += ar => new TestHttpWebResponse(null, new StreamingContext());
            twr.OnEndGetResponse += ar => 
            {
                SerializationInfo si = new SerializationInfo(typeof(HttpWebResponse), new FormatterConverter());
                StreamingContext sc = new StreamingContext();
//                WebHeaderCollection headers = new WebHeaderCollection();
//                si.AddValue("m_HttpResponseHeaders", headers);
                si.AddValue("uri", new Uri("test://arrg"));
//                si.AddValue("m_Certificate", null);
                si.AddValue("version", HttpVersion.Version11);
                si.AddValue("statusCode", HttpStatusCode.NotFound);
                si.AddValue("contentLength", 0);
                si.AddValue("method", "GET");
                si.AddValue("statusDescription", "Not Found");
                si.AddValue("contentType", null);
                si.AddValue("cookieCollection", new CookieCollection());

                TestHttpWebResponse thwr = new TestHttpWebResponse(si, sc);
                thwr.Response = rawResponse;

                throw new WebException("no message", null, WebExceptionStatus.ProtocolError, thwr);
            };

            twrc.NextRequest = twr;

            WebRequest.RegisterPrefix("test", twrc);
            HttpRequestClass hr = new HttpRequestClass();
            hr.Url = "test://something";
            hr.SendRequest();

            Assert.That(hr.Status, Is.EqualTo((int)HttpStatusCode.NotFound));
            Assert.That(hr.ResponseBody, Is.EqualTo(rawResponse));
        }
Пример #3
0
        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;
        }
Пример #4
0
        public UUID StartHttpRequest(
            uint localID, UUID itemID, string url, List <string> parameters, Dictionary <string, string> headers, string body,
            out HttpInitialRequestStatus status)
        {
            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     = httpTimeout;
            htc.OutboundBody    = body;
            htc.ResponseHeaders = headers;
            htc.proxyurl        = m_proxyurl;
            htc.proxyexcepts    = m_proxyexcepts;

            // Same number as default HttpWebRequest.MaximumAutomaticRedirections
            htc.MaxRedirects = 50;

            if (StartHttpRequest(htc))
            {
                status = HttpInitialRequestStatus.OK;
                return(htc.ReqID);
            }
            else
            {
                status = HttpInitialRequestStatus.DISALLOWED_BY_FILTER;
                return(UUID.Zero);
            }
        }
Пример #5
0
        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);
        }
Пример #6
0
        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;
        }
Пример #7
0
        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;
        }
Пример #8
0
        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);
        }