Example #1
0
 public void AddRoute(string method, string path, HttpRouteDelegate routeDelegate)
 {
     this.routeTable.Add(method + "_" + path, routeDelegate);
 }
Example #2
0
        private void ProceedRequest(object obj)
        {
            LinkedListNode <HttpRequest> lln = (LinkedListNode <HttpRequest>)obj;

            try
            {
                lln.Value.ParseHeaders();

                this.upnpServer.RootDevice.OnLogEvent(string.Format("{0} {1}", lln.Value.Method, lln.Value.Url));

                HttpRouteDelegate del = GetRoute(lln.Value.Method, lln.Value.Url);
                if (del == null)
                {
                    string[] fragments = lln.Value.Url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = fragments.Length; i >= 0; i--)
                    {
                        string str = "/";
                        for (int j = 0; j < i; j++)
                        {
                            str += fragments[j] + "/";
                        }
                        str += "*";

                        if ((del = GetRoute(lln.Value.Method, str)) != null)
                        {
                            break;
                        }
                    }
                    if (del == null)
                    {
                        throw new HttpException(404, "Not found - " + lln.Value.Url);
                    }
                }

                del(lln.Value);
            }
            catch (HttpException ex)
            {
                this.upnpServer.RootDevice.OnLogEvent(ex.Message);

                HttpResponse response = lln.Value.GetResponse();
                response.SetStateCode(ex.Code);
                try { response.SendHeaders(); }
                catch { }
            }
            catch (SoapException ex)
            {
                this.upnpServer.RootDevice.OnLogEvent(ex.Message);

                HttpResponse response = lln.Value.GetResponse();
                try { response.SendSoapErrorHeadersBody(ex.Code, ex.Message); }
                catch { }
            }
            catch (Exception ex)
            {
                this.upnpServer.RootDevice.OnLogEvent(ex.Message);

                HttpResponse response = lln.Value.GetResponse();
                response.SetStateCode(500);
                try { response.SendHeaders(); }
                catch { }
            }

            //Odstrani uzol poziadavky zo zretazeneho zoznamu
            lock (this.requestList)
            {
                this.requestList.Remove(lln);

                this.upnpServer.RootDevice.OnLogEvent(this.requestList.Count);
            }

            //Pockat kratky cas kym sa uzatvori spojenie
            Thread.Sleep(10);
            //Uzatvorenie spojenia
            try { lln.Value.CloseStream(); }
            catch { }
        }