当前位置: 首页>>代码示例>>C#>>正文


C# HTTPMessage.GetTag方法代码示例

本文整理汇总了C#中OpenSource.UPnP.HTTPMessage.GetTag方法的典型用法代码示例。如果您正苦于以下问题:C# HTTPMessage.GetTag方法的具体用法?C# HTTPMessage.GetTag怎么用?C# HTTPMessage.GetTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenSource.UPnP.HTTPMessage的用法示例。


在下文中一共展示了HTTPMessage.GetTag方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReceiveSink

        private void ReceiveSink(HTTPSession sender, HTTPMessage msg)
        {
            StateData sd = (StateData)sender.StateObject;
            object Tag = sd.Tag;

            if (msg.Version == "1.0" || msg.Version == "0.9")
            {
                sender.Close();
            }
            else
            {
                if (msg.GetTag("Connection").ToUpper() == "CLOSE")
                {
                    sender.Close();
                }
            }


            if (OnResponse != null) OnResponse(this, msg, Tag);
            // If I don't set this to null, this holds a strong reference, resulting in
            // possible memory leaks
            sender.StateObject = null;
            lock (TagQueue)
            {
                if (TagQueue.Count == 0)
                {
                    this.IdleTimeout = true;
                    KeepAliveTimer.Add(this.GetHashCode(), 10);
                }
            }
        }
开发者ID:Scannow,项目名称:SWYH,代码行数:31,代码来源:HTTPRequest.cs

示例2: ParseByteArray

        /// <summary>
        /// Parses a Byte Array at a specific location, and builds a Packet.
        /// </summary>
        /// <param name="buffer">The Array of Bytes</param>
        /// <param name="indx">The Start Index</param>
        /// <param name="count">The number of Bytes to process</param>
        /// <returns></returns>
        public static HTTPMessage ParseByteArray(byte[] buffer, int indx, int count)
        {
            HTTPMessage TheMessage = new HTTPMessage();
            UTF8Encoding UTF8 = new UTF8Encoding();
            String TempData = UTF8.GetString(buffer,indx,count);
            DText parser = new DText();
            String TempString;

            int idx = TempData.IndexOf("\r\n\r\n");
            if (idx < 0) return null;
            TempData = TempData.Substring(0,idx);

            parser.ATTRMARK = "\r\n";
            parser.MULTMARK = ":";
            parser[0] = TempData;
            string CurrentLine = parser[1];

            DText HdrParser = new DText();
            HdrParser.ATTRMARK = " ";
            HdrParser.MULTMARK = "/";
            HdrParser[0] = CurrentLine;

            if (CurrentLine.ToUpper().StartsWith("HTTP/")==true)
            {
                TheMessage.ResponseCode = int.Parse(HdrParser[2]);
                int s1 = CurrentLine.IndexOf(" ");
                s1 = CurrentLine.IndexOf(" ",s1+1);
                TheMessage.ResponseData = HTTPMessage.UnEscapeString(CurrentLine.Substring(s1));
                try
                {
                    TheMessage.Version = HdrParser[1,2];
                }
                catch(Exception)
                {
                    TheMessage.Version = "0.9";
                }
            }
            else
            {
                TheMessage.Directive = HdrParser[1];
                TempString = CurrentLine.Substring(CurrentLine.LastIndexOf(" ") + 1);
                if (TempString.ToUpper().StartsWith("HTTP/")==false)
                {
                    TheMessage.Version = "0.9";
                    TheMessage.DirectiveObj = HTTPMessage.UnEscapeString(TempString);
                }
                else
                {
                    TheMessage.Version = TempString.Substring(TempString.IndexOf("/")+1);
                    int fs = CurrentLine.IndexOf(" ") + 1;
                    TheMessage.DirectiveObj = HTTPMessage.UnEscapeString(CurrentLine.Substring(
                        fs,
                        CurrentLine.Length-fs-TempString.Length-1));
                }
            }
            String Tag="";
            String TagData="";

            for(int line=2;line<=parser.DCOUNT();++line)
            {
                if (Tag!="" && parser[line,1].StartsWith(" "))
                {
                    TagData = parser[line,1].Substring(1);
                }
                else
                {
                    Tag = parser[line,1];
                    TagData = "";
                    for(int i=2;i<=parser.DCOUNT(line);++i)
                    {
                        if (TagData=="")
                        {
                            TagData = parser[line,i];
                        }
                        else
                        {
                            TagData = TagData + parser.MULTMARK + parser[line,i];
                        }
                    }
                }
                TheMessage.AppendTag(Tag,TagData);
            }
            int cl=0;
            if (TheMessage.HasTag("Content-Length"))
            {
                try
                {
                    cl = int.Parse(TheMessage.GetTag("Content-Length"));
                }
                catch(Exception)
                {
                    cl = -1;
                }
//.........这里部分代码省略.........
开发者ID:nothingmn,项目名称:UPnP-for-C---Intel-,代码行数:101,代码来源:HTTPMessage.cs

示例3: HandleSubscribeResponse

        private void HandleSubscribeResponse(HTTPRequest sender, HTTPMessage response, object Tag)
        {
            UPnPEventSubscribeHandler CB = (UPnPEventSubscribeHandler)Tag;
            SubscribeRequestTable.Remove(sender);
            sender.Dispose();
            if (response != null)
            {
                if (response.StatusCode != 200)
                {
                    if (CB != null)
                    {
                        CB(this, false);
                    }
                    else
                    {
                        if (OnSubscribe != null) OnSubscribe(this, false);
                    }
                }
                else
                {
                    CurrentSID = response.GetTag("SID");
                    if (CB != null)
                    {
                        CB(this, true);
                    }
                    else
                    {
                        if (OnSubscribe != null) OnSubscribe(this, true);
                    }

                    if (CurrentTimeout != 0)
                    {
                        EventLogger.Log(this, System.Diagnostics.EventLogEntryType.SuccessAudit, "SUBSCRIBE [" + this.CurrentSID + "] Duration: " + CurrentTimeout.ToString() + " <" + DateTime.Now.ToLongTimeString() + ">");
                        SubscribeCycle.Add(this.GetHashCode(), CurrentTimeout / 2);
                    }
                }
            }
            else
            {
                if (CB != null)
                {
                    CB(this, false);
                }
                else
                {
                    if (OnSubscribe != null) OnSubscribe(this, false);
                }
            }
        }
开发者ID:rvodden,项目名称:upnp-developertools-old,代码行数:49,代码来源:UPnPService.cs

示例4: OnReceiveSink2

        private void OnReceiveSink2(byte[] buffer, IPEndPoint remote, IPEndPoint local)
        {
            HTTPMessage msg;

            try
            {
                msg = HTTPMessage.ParseByteArray(buffer, 0, buffer.Length);
            }
            catch (Exception ex)
            {
                OpenSource.Utilities.EventLogger.Log(ex);
                msg = new HTTPMessage();
                msg.Directive = "---";
                msg.DirectiveObj = "---";
                msg.BodyBuffer = buffer;
            }
            msg.LocalEndPoint = local;
            msg.RemoteEndPoint = remote;

            DText parser = new DText();

            String Location = msg.GetTag("Location");
            int MaxAge = 0;
            String ma = msg.GetTag("Cache-Control").Trim();
            if (ma != "")
            {
                parser.ATTRMARK = ",";
                parser.MULTMARK = "=";
                parser[0] = ma;
                for (int i = 1; i <= parser.DCOUNT(); ++i)
                {
                    if (parser[i, 1].Trim().ToUpper() == "MAX-AGE")
                    {
                        MaxAge = int.Parse(parser[i, 2].Trim());
                        break;
                    }
                }
            }
            ma = msg.GetTag("USN");
            String USN = ma.Substring(ma.IndexOf(":") + 1);
            String ST = msg.GetTag("ST");
            if (USN.IndexOf("::") != -1) USN = USN.Substring(0, USN.IndexOf("::"));
            OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.SuccessAudit, msg.RemoteEndPoint.ToString());
            if (OnSearch != null) OnSearch(msg.RemoteEndPoint, msg.LocalEndPoint, new Uri(Location), USN, ST, MaxAge);
        }
开发者ID:Scannow,项目名称:SWYH,代码行数:45,代码来源:UPnPControlPoint.cs

示例5: EventProcesser

        private void EventProcesser(UPnPDevice sender, HTTPMessage msg, HTTPSession WebSession, string VirtualDir)
        {
            if (ControlPointOnly == true)
            {
                String Method = msg.Directive;
                HTTPMessage Response = new HTTPMessage();

                if (Method != "NOTIFY")
                {
                    Response.StatusCode = 405;
                    Response.StatusData = Method + " not supported";
                    WebSession.Send(Response);
                    return; // Other methods are unknown to us
                }
                else if (Method == "NOTIFY")
                {
                    for (int id = 0; id < Services.Length; ++id)
                    {
                        //						SSDP.ParseURL(Services[id].__eventurl,out WebIP, out WebPort, out WebData);
                        //						if (WebData==MethodData)
                        //						{
                        if (Services[id].IsYourEvent(msg.GetTag("SID")) == true)
                        {
                            Response.StatusCode = 200;
                            Response.StatusData = "OK";
                            WebSession.Send(Response);

                            Services[id]._TriggerEvent(msg.GetTag("SID"), long.Parse(msg.GetTag("SEQ")), msg.StringBuffer, 0);
                            break;
                        }
                        //						}
                    }
                }
            }
        }
开发者ID:genielabs,项目名称:intel-upnp-dlna,代码行数:35,代码来源:UPnPDevice.cs

示例6: HandleWebRequest

        private void HandleWebRequest(HTTPMessage msg, HTTPSession WebSession)
        {
            DText parser = new DText();
            HTTPMessage Response = new HTTPMessage();
            HTTPMessage Response2 = null;
            String Method = msg.Directive;
            String MethodData = msg.DirectiveObj;

            if (WebSession.InternalStateObject != null)
            {
                HTTPMessage _msg = (HTTPMessage)msg.Clone();
                object[] state = (object[])WebSession.InternalStateObject;
                _msg.DirectiveObj = (string)state[1];
                VirtualDirectoryHandler t = (VirtualDirectoryHandler)state[2];
                WebSession.InternalStateObject = null;
                t(this, _msg, WebSession, (string)state[0]);
                return;

            }

            if ((Method != "GET") && (Method != "HEAD") && (Method != "POST") &&
                (Method != "SUBSCRIBE") && (Method != "UNSUBSCRIBE") &&
                (Method != "NOTIFY"))
            {
                Response.StatusCode = 405;
                Response.StatusData = Method + " not supported";
                WebSession.Send(Response);
                return; // Other methods are unknown to us
            }

            // Process Headers
            if (Method == "GET" || Method == "HEAD")
            {
                try
                {
                    Response = Get(MethodData, WebSession.Source);
                }
                catch (UPnPCustomException ce)
                {
                    OpenSource.Utilities.EventLogger.Log(ce);
                    Response.StatusCode = ce.ErrorCode;
                    Response.StatusData = ce.ErrorDescription;
                    WebSession.Send(Response);
                    return;
                }
                catch (Exception e)
                {
                    OpenSource.Utilities.EventLogger.Log(e);
                    Response.StatusCode = 500;
                    Response.StatusData = "Internal";
                    Response.StringBuffer = e.ToString();
                }
                if (Method == "HEAD")
                {
                    Response.BodyBuffer = null;
                }
                WebSession.Send(Response);
            }

            if (Method == "POST")
            {
                //InvokerInfo[Thread.CurrentThread.GetHashCode()] = WebSession;
                try
                {
                    Response = Post(MethodData, msg.StringBuffer, msg.GetTag("SOAPACTION"), WebSession);
                }
                catch (DelayedResponseException ex)
                {
                    OpenSource.Utilities.EventLogger.Log(ex);
                    InvokerInfo.Remove(Thread.CurrentThread.GetHashCode());
                    WebSession.StopReading();
                    return;
                }
                catch (UPnPCustomException ce)
                {
                    OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Error, "UPnP Error [" + ce.ErrorCode.ToString() + "] " + ce.ErrorDescription);
                    Response.StatusCode = 500;
                    Response.StatusData = "Internal";
                    Response.StringBuffer = BuildErrorBody(ce);
                    WebSession.Send(Response);
                    InvokerInfo.Remove(Thread.CurrentThread.GetHashCode());
                    return;
                }
                catch (UPnPInvokeException ie)
                {
                    Response.StatusCode = 500;
                    Response.StatusData = "Internal";
                    if (ie.UPNP != null)
                    {
                        OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Error, "UPnP Error [" + ie.UPNP.ErrorCode.ToString() + "] " + ie.UPNP.ErrorDescription);
                        Response.StringBuffer = BuildErrorBody(ie.UPNP);
                    }
                    else
                    {
                        OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Error, "UPnP Invocation Error [" + ie.MethodName + "] " + ie.Message);
                        Response.StringBuffer = BuildErrorBody(new UPnPCustomException(500, ie.Message));
                    }
                    WebSession.Send(Response);
                    InvokerInfo.Remove(Thread.CurrentThread.GetHashCode());
                    return;
//.........这里部分代码省略.........
开发者ID:genielabs,项目名称:intel-upnp-dlna,代码行数:101,代码来源:UPnPDevice.cs

示例7: ProcessPacket

        private void ProcessPacket(HTTPMessage msg, IPEndPoint src, IPEndPoint local)
        {
            if (OnSniffPacket != null) OnSniffPacket(src, null, msg);

            DText parser = new DText();
            parser.ATTRMARK = "::";

            bool Alive = false;
            String UDN = msg.GetTag("USN");

            parser[0] = UDN;
            String USN = parser[1];
            USN = USN.Substring(USN.IndexOf(":") + 1);
            String ST = parser[2];
            int MaxAge = 0;

            String NTS = msg.GetTag("NTS").ToUpper();
            if (NTS == "SSDP:ALIVE")
            {
                Alive = true;
                String ma = msg.GetTag("Cache-Control").Trim();
                if (ma != "")
                {
                    parser.ATTRMARK = ",";
                    parser.MULTMARK = "=";
                    parser[0] = ma;
                    for (int i = 1; i <= parser.DCOUNT(); ++i)
                    {
                        if (parser[i, 1].Trim().ToUpper() == "MAX-AGE")
                        {
                            MaxAge = int.Parse(parser[i, 2].Trim());
                            break;
                        }
                    }
                }
            }

            if (msg.Directive == "NOTIFY" && OnNotify != null)
            {
                Uri locuri = null;
                string location = msg.GetTag("Location");
                if (location != null && location.Length > 0) { try { locuri = new Uri(location); } catch (Exception) { } }
                OnNotify(src, msg.LocalEndPoint, locuri, Alive, USN, ST, MaxAge, msg);
            }
            else if (msg.Directive == "M-SEARCH" && OnSearch != null)
            {
                if (ValidateSearchPacket(msg) == false) return;
                int MaxTimer = int.Parse(msg.GetTag("MX"));
                SearchStruct SearchData = new SearchStruct();
                SearchData.ST = msg.GetTag("ST");
                SearchData.Source = src;
                SearchData.Local = local;
                SearchTimer.Add(SearchData, RandomGenerator.Next(0, MaxTimer));
            }
        }
开发者ID:Tieske,项目名称:Developer-Tools-for-UPnP-Technologies,代码行数:55,代码来源:SSDP.cs

示例8: ValidateSearchPacket

 private bool ValidateSearchPacket(HTTPMessage msg)
 {
     int MX = 0;
     if (msg.GetTag("MAN") != "\"ssdp:discover\"") return false; // { throw (new InvalidSearchPacketException("Invalid MAN")); }
     if (msg.DirectiveObj != "*") return false; // { throw (new InvalidSearchPacketException("Expected * in RequestLine")); }
     if (double.Parse(msg.Version, new CultureInfo("en-US").NumberFormat) < (double)1.1) return false; // { throw (new InvalidSearchPacketException("Version must be at least 1.1")); }
     if (int.TryParse(msg.GetTag("MX"), out MX) == false || MX <= 0) return false; // { throw (new InvalidSearchPacketException("MX must be a positive integer")); }
     return true;
 }
开发者ID:Tieske,项目名称:Developer-Tools-for-UPnP-Technologies,代码行数:9,代码来源:SSDP.cs

示例9: HandleReceive

		private void HandleReceive(AsyncSocket sender, Byte[] buffer, int BeginPointer, int BufferSize, int BytesRead, IPEndPoint source, IPEndPoint remote)
		{

			if (BytesRead!=0)
			{
				OnSniffEvent.Fire(buffer,BufferSize-BytesRead, BytesRead);
			}
		

			if (this.FinishedHeader==false)
			{
				if (BufferSize<4)
				{
					sender.BufferReadLength = 1;
					sender.BufferBeginPointer = 0;
					return;
				}
				/* This is New */
				for(int i=4;i<BufferSize-4;++i)
				{
					if ((buffer[i-4]==13)&&(buffer[i-3]==10)&&
						(buffer[i-2]==13)&&(buffer[i-1]==10))
					{
						BufferSize = i;
						break;
					}
				}


				if ((buffer[BufferSize-4]==13)&&(buffer[BufferSize-3]==10)&&
					(buffer[BufferSize-2]==13)&&(buffer[BufferSize-1]==10))
				{
					// End Of Headers
					Headers = HTTPMessage.ParseByteArray(buffer,0,BufferSize);
					

					if (Headers.StatusCode!=-1)
					{
						if (Headers.StatusCode>=100 && Headers.StatusCode<=199)
						{
							//Informational
							if (OpenSource.Utilities.EventLogger.Enabled)
							{
								OpenSource.Utilities.EventLogger.Log(this,System.Diagnostics.EventLogEntryType.Information,"<<IGNORING>>\r\n" + Headers.StringPacket);
							}
//							OnHeaderEvent.Fire(this,Headers, UserStream);
							OnSniffPacketEvent.Fire(this,Headers);
//							OnReceiveEvent.Fire(this, Headers);
//							DONE_ReadingPacket();
							BeginHeader(BufferSize);
							return;
						}

						if (Headers.StatusCode==204 || Headers.StatusCode==304)
						{
							//No Body or No Change
							if (OpenSource.Utilities.EventLogger.Enabled)
							{
								OpenSource.Utilities.EventLogger.Log(this,System.Diagnostics.EventLogEntryType.Information,Headers.StringPacket);
							}
							OnHeaderEvent.Fire(this,Headers, UserStream);
							OnSniffPacketEvent.Fire(this,Headers);
							OnReceiveEvent.Fire(this, Headers);
							DONE_ReadingPacket();
							BeginHeader(BufferSize);
							return;
						}
					}
					else
					{
						SET_START_OF_REQUEST();
					}

					FinishedHeader = true;
					if (Headers.GetTag("Content-Length")=="")
					{
						if (Headers.GetTag("Transfer-Encoding").ToUpper()=="CHUNKED")
						{
							IsChunked = true;
						}
						else
						{
							if (Headers.StatusCode!=-1)
							{
								this.NeedToWaitToClose = true;
							}
						}
					}
					else
					{
						if (Headers.GetTag("Transfer-Encoding").ToUpper()=="CHUNKED")
						{
							IsChunked = true;
						}
						else
						{
							BodySize = int.Parse(Headers.GetTag("Content-Length"));
						}
					}
					if (Headers.GetTag("Connection").ToUpper()=="CLOSE")
//.........这里部分代码省略.........
开发者ID:Scannow,项目名称:SWYH,代码行数:101,代码来源:HTTPSession.cs

示例10: Start

        public override void Start(UPnPDevice device)
        {
            if(!Enabled) return;

            UPnPDevice dv = device;
            while(dv.ParentDevice!=null)
            {
                dv = dv.ParentDevice;
            }

            state = UPnPTestStates.Running;
            UPnPService[] _S = device.GetServices("urn:");

            foreach(UPnPService s in _S)
            {
                bool ok = false;
                foreach(UPnPStateVariable v in s.GetStateVariables())
                {
                    if(v.SendEvent)
                    {
                        ok = true;
                        break;
                    }
                }
                if(ok)
                {

                    UPnPDebugObject d = new UPnPDebugObject(s);
                    Uri EventUri = new Uri((string)d.GetField("__eventurl"));

                    IPEndPoint dest = new IPEndPoint(IPAddress.Parse(EventUri.Host),EventUri.Port);
                    HTTPMessage R = new HTTPMessage();
                    R.Directive = "SUBSCRIBE";
                    R.DirectiveObj = HTTPMessage.UnEscapeString(EventUri.PathAndQuery);
                    R.AddTag("Host",dest.ToString());
                    R.AddTag("Callback","<http://" + dv.InterfaceToHost.ToString()+ ":" + NetworkInfo.GetFreePort(10000,50000,dv.InterfaceToHost).ToString() + ">");
                    //R.AddTag("Callback","<http://127.0.0.1:55555>");
                    R.AddTag("NT","upnp:event");
                    R.AddTag("Timeout","Second-15");

                    System.Console.WriteLine(R.GetTag("Callback"));

                    MRE.Reset();
                    SID = "";
                    StartCountDown(30);
                    HTTPRequest rq = new HTTPRequest();
                    rq.OnResponse += new HTTPRequest.RequestHandler(SubscribeSink);

                    AddHTTPMessage(R);

                    rq.PipelineRequest(dest,R,s);
                    MRE.WaitOne(30000,false);
                    AbortCountDown();

                    if (SID=="")
                    {
                        AddEvent(LogImportance.Critical,"Subscribe","SUBSCRIBE: " + s.ServiceURN + " << FAILED >>");
                        AddEvent(LogImportance.Remark,"Subscribe","Aborting tests");

                        result = "Subscription test failed."; // TODO
                        state = UPnPTestStates.Failed;
                        return;
                    }
                    else
                    {
                        AddEvent(LogImportance.Remark,"Subscribe","SUBSCRIBE: " + s.ServiceURN + " << OK >>");

                        // Renew Test
                        R = new HTTPMessage();
                        R.Directive = "SUBSCRIBE";
                        R.DirectiveObj = HTTPMessage.UnEscapeString(EventUri.PathAndQuery);
                        R.AddTag("Host",dest.ToString());
                        R.AddTag("SID",SID);
                        R.AddTag("Timeout","Second-15");
                        StartCountDown(30);
                        SID = "";
                        MRE.Reset();

                        AddHTTPMessage(R);

                        rq = new HTTPRequest();
                        rq.OnResponse += new HTTPRequest.RequestHandler(SubscribeSink);
                        rq.PipelineRequest(dest,R,s);

                        MRE.WaitOne(30000,false);
                        AbortCountDown();

                        if (SID=="")
                        {
                            AddEvent(LogImportance.Critical,"Subscribe","SUBSCRIBE (Renew): " + s.ServiceURN + " << FAILED >>");
                            AddEvent(LogImportance.Remark,"Subscribe","Aborting tests");

                            result = "Subscription test failed."; // TODO
                            state = UPnPTestStates.Failed;
                            return;
                        }
                        else
                        {
                            AddEvent(LogImportance.Remark,"Subscribe","SUBSCRIBE (Renew): " + s.ServiceURN + " << OK >>");

//.........这里部分代码省略.........
开发者ID:amadare,项目名称:DeveloperToolsForUPnP,代码行数:101,代码来源:UPnPTestSubscribe.cs

示例11: SubscribeSink

        private void SubscribeSink(HTTPRequest sender, HTTPMessage MSG, object Tag)
        {
            if (MSG!=null)
            {
                AddPacket(MSG);

                if (MSG.StatusCode==200)
                {
                    SID = MSG.GetTag("SID");
                }
            }
            MRE.Set();
        }
开发者ID:amadare,项目名称:DeveloperToolsForUPnP,代码行数:13,代码来源:UPnPTestSubscribe.cs

示例12: HandleGetOrHeadRequest


//.........这里部分代码省略.........
                        // no stream can be sent in response to the request

                        if (mapping.RedirectedStream != null)
                        {
                            lock (session)
                            {
                                // get the intended length, if known
                                long expectedLength = -1;
                                if (mapping.OverrideRedirectedStreamLength)
                                {
                                    expectedLength = mapping.ExpectedStreamLength;
                                }
                                else
                                {
                                    expectedLength = mapping.RedirectedStream.Length;
                                }

                                if (String.Compare(msg.Directive, "HEAD", true) == 0)
                                {
                                    // must be a head request - reply with 200/OK, content type, content length
                                    HTTPMessage head = new HTTPMessage();
                                    head.StatusCode = 200;
                                    head.StatusData = "OK";
                                    head.ContentType = type;
                                    if (expectedLength >= 0)
                                    {
                                        // if we can calculate the length,
                                        // then we provide a content-length and
                                        // also indicate that range requests can be
                                        // handled.

                                        head.OverrideContentLength = true;

                                        string rangeStr = msg.GetTag("RANGE");
                                        if ((rangeStr == null) || (rangeStr == ""))
                                        {
                                            head.AddTag("CONTENT-LENGTH", expectedLength.ToString());
                                            head.AddTag("ACCEPT-RANGES", "bytes");
                                        }
                                        else
                                        {
                                            ArrayList rangeSets = new ArrayList();
                                            head.StatusCode = 206;
                                            AddRangeSets(rangeSets, rangeStr.Trim().ToLower(), expectedLength);
                                            if (rangeSets.Count == 1)
                                            {
                                                head.AddTag("Content-Range", "bytes " + ((HTTPSession.Range)(rangeSets[0])).Position.ToString() + "-" + ((int)(((HTTPSession.Range)(rangeSets[0])).Position+((HTTPSession.Range)(rangeSets[0])).Length-1)).ToString() + "/" + expectedLength.ToString());
                                                head.AddTag("Content-Length", ((HTTPSession.Range)(rangeSets[0])).Length.ToString());
                                            }
                                        }
                                    }
                                    else
                                    {
                                        // can't calculate length => can't do range
                                        head.AddTag("ACCEPT-RANGES", "none");
                                    }
                                    session.Send(head);
                                    is404 = false;
                                }
                                else
                                {
                                    ArrayList rangeSets = new ArrayList();
                                    string rangeStr = msg.GetTag("RANGE");

                                    // Only allow range requests for content where we have the
                                    // entire length and also only for requests that have
开发者ID:amadare,项目名称:DeveloperToolsForUPnP,代码行数:67,代码来源:MediaServerDevice.cs

示例13: ExtractContentLength

        /// <summary>
        /// Examines an <see cref="HTTPMessage"/> object and
        /// attempts to find the content length of the message body.
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        private long ExtractContentLength(HTTPMessage msg)
        {
            long expectedLength = 0;
            string contentLengthString = msg.GetTag("CONTENT-LENGTH");
            try
            {
                expectedLength = long.Parse(contentLengthString);
            }
            catch{}

            return expectedLength;
        }
开发者ID:amadare,项目名称:DeveloperToolsForUPnP,代码行数:18,代码来源:MediaServerDevice.cs


注:本文中的OpenSource.UPnP.HTTPMessage.GetTag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。