Commits

Jose F. Romaniello  committed 84b4f9a

minor

  • Participants
  • Parent commits f2b8542

Comments (0)

Files changed (3)

File AsyncHttp/Program.cs

 {
     class Program
     {
-        static void Main(string[] args)
+        static void Main()
         {
             var subject = new Subject<string>();
 
             {
                 var listeners = server
                         .Where(ctx => ctx.Request.HttpMethod == "GET")
-                        .Subscribe(ctx => subject
-                                                .Take(1)
-                                                .Subscribe(m => ctx.Respond(new StringResponse(m))));
+                        .Subscribe(ctx => subject.Take(1)
+                                                 .Subscribe(m => ctx.Respond(new StringResponse(m))));
 
                 var publisher = server
                     .Where(ctx => ctx.Request.HttpMethod == "POST")
-                    .Subscribe(ctx => ctx.Request.InputStream.ReadBytes(int.Parse(ctx.Request.Headers["Content-Length"].First()))
+                    .Subscribe(ctx => ctx.Request.InputStream.ReadBytes(ctx.Request.ContentLength)
                                           .Subscribe(bts =>
                                                          {
                                                              subject.OnNext(Encoding.UTF8.GetString(bts));

File AsyncHttp/Server/HttpServer.cs

         private IObservable<RequestContext> ObservableHttpContext()
         {
             return Observable.Create<RequestContext>(obs =>
-                                Observable.FromAsyncPattern<HttpListenerContext>(listener.BeginGetContext, listener.EndGetContext)()
+                                Observable.FromAsyncPattern<HttpListenerContext>(listener.BeginGetContext, 
+                                                                                 listener.EndGetContext)()
                                           .Select(c => new RequestContext(c.Request, c.Response))
                                           .Subscribe(obs))
                              .Repeat()

File AsyncHttp/Server/Request.cs

 using System.Collections.Generic;
 using System.IO;
+using System.Linq;
 
 namespace AsyncHttp.Server
 {
         public IDictionary<string, IEnumerable<string>> Headers { get; set; }
         public Stream InputStream { get; set; }
         public string RawUrl { get; set; }
+        public int ContentLength
+        {
+            get { return int.Parse(Headers["Content-Length"].First()); }
+        }
     }
 }