Exemplo n.º 1
0
        public void ParseRequestMessage()
        {
            var message = HttpMessage.Parse("request:fa464f02-8c02-4ee3-a8ca-66301688b5c4\n" +
                                            "GET /foo HTTP/1.1\r\n" +
                                            "Host: example.org\r\n" +
                                            "\r\n");

            Assert.NotNull(message);

            Assert.NotNull(message.HttpRequestMessage);
            Assert.True(message.IsRequest);
            Assert.Equal("http://example.org/foo", message.HttpRequestMessage.RequestUri.AbsoluteUri);
            Assert.Equal("fa464f02-8c02-4ee3-a8ca-66301688b5c4", message.MessageId.ToString());
            Assert.Equal(HttpMethod.Get, message.HttpRequestMessage.Method);
        }
Exemplo n.º 2
0
        public async Task ParseResponseMessage()
        {
            var message = HttpMessage.Parse("response:fa464f02-8c02-4ee3-a8ca-66301688b5c4\n" +
                                            "HTTP/1.1 200 OK\r\n" +
                                            "Content-Type: text/plain\r\n" +
                                            "Content-Length: 12\r\n" +
                                            "\r\n" +
                                            "Hello World!");

            Assert.NotNull(message);

            Assert.NotNull(message.HttpResponseMessage);
            Assert.False(message.IsRequest);
            Assert.Equal("fa464f02-8c02-4ee3-a8ca-66301688b5c4", message.MessageId.ToString());
            Assert.Equal(HttpStatusCode.OK, message.HttpResponseMessage.StatusCode);
            Assert.Equal("Hello World!", await message.HttpResponseMessage.Content.ReadAsStringAsync());
        }
Exemplo n.º 3
0
 /// <summary>
 /// Called when [server data received].
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="EventArgs{T}.Core.Net.NetworkData&gt;"/> instance containing the event data.</param>
 protected virtual void OnServerDataReceived(object sender, EventArgs <NetworkData> e)
 {
     // Queue this response to be processed
     ThreadPool.QueueUserWorkItem(data =>
     {
         try
         {
             // Parse our message and fire our event
             using (var stream = new MemoryStream(e.Value.Buffer, 0, e.Value.Length))
             {
                 this.OnResultFound(new SsdpMessage(HttpMessage.Parse(stream), e.Value.RemoteIPEndpoint));
             }
         }
         catch (ArgumentException ex)
         {
             System.Diagnostics.Trace.TraceError("Failed to parse SSDP response: {0}", ex.ToString());
         }
     });
 }
Exemplo n.º 4
0
        protected override void OnDataReceived(NetworkData args)
        {
            base.OnDataReceived(args);

            // Queue this response to be processed
            ThreadPool.QueueUserWorkItem(data =>
            {
                try
                {
                    // Parse our message and fire our event
                    using (var stream = new MemoryStream(args.Buffer, 0, args.Length))
                    {
                        this.OnSsdpMessageReceived(new SsdpMessage(HttpMessage.Parse(stream), args.RemoteIPEndpoint));
                    }
                }
                catch (ArgumentException ex)
                {
                    System.Diagnostics.Trace.TraceError("Failed to parse SSDP response: {0}", ex.ToString());
                }
            });
        }