示例#1
0
 public HttpRequest(IHttpTransaction transaction, SocketStream stream)
 {
     Transaction = transaction;
     Socket = stream;
     RemoteAddress = stream.Address;
     RemotePort = stream.Port;
 }
示例#2
0
 public HttpRequest(IHttpTransaction transaction, SocketStream stream)
 {
     Transaction   = transaction;
     Socket        = stream;
     RemoteAddress = stream.Address;
     RemotePort    = stream.Port;
 }
示例#3
0
 public HttpRequest(IHttpTransaction transaction, Socket stream)
     : base(transaction.Context)
 {
     Transaction = transaction;
     Socket = stream;
     RemoteAddress = stream.Address;
     RemotePort = stream.Port;
 }
示例#4
0
 public HttpRequest(IHttpTransaction transaction, ITcpSocket stream)
     : base(transaction.Context)
 {
     Transaction   = transaction;
     Socket        = stream;
     RemoteAddress = stream.RemoteEndpoint.Address.ToString();
     RemotePort    = stream.RemoteEndpoint.Port;
 }
示例#5
0
 public HttpRequest(IHttpTransaction transaction, ITcpSocket stream)
     : base(transaction.Context)
 {
     Transaction = transaction;
     Socket = stream;
     RemoteAddress = stream.RemoteEndpoint.Address.ToString();
     RemotePort = stream.RemoteEndpoint.Port;
 }
示例#6
0
 public HttpRequest(IHttpTransaction transaction, Socket stream)
     : base(transaction.Context)
 {
     Transaction   = transaction;
     Socket        = stream;
     RemoteAddress = stream.Address;
     RemotePort    = stream.Port;
 }
示例#7
0
        public Pipeline(ManosApp app, IHttpTransaction transaction)
        {
            this.app = app;
            this.transaction = transaction;

            pending = AppHost.Pipes == null ? 1 : AppHost.Pipes.Count;
            step = PipelineStep.PreProcess;
            handle = GCHandle.Alloc (this);

            transaction.Response.OnEnd += HandleEnd;
        }
示例#8
0
文件: ManosApp.cs 项目: KevinT/manos
 public void OnPostProcessRequest(ManosApp app, IHttpTransaction transaction)
 {
     foreach (IManosPipe pipe in AppHost.Pipes) {
         try {
             pipe.OnPostProcessRequest (this, transaction);
         } catch (Exception e) {
             Console.Error.WriteLine ("Exception in {0}::OnPostProcessRequest.", pipe);
             Console.Error.WriteLine (e);
         }
     }
 }
示例#9
0
        public HttpRequest(IHttpTransaction transaction, HttpHeaders headers, string method, string resource, bool support_1_1)
        {
            Transaction = transaction;
            Headers = headers;
            Method = method;
            ResourceUri = resource;
            Http_1_1_Supported = support_1_1;

            SetEncoding ();
            SetPathAndQuery ();
        }
示例#10
0
文件: Pipeline.cs 项目: txdv/manos
        public Pipeline(ManosApp app, IHttpTransaction transaction)
        {
            this.app         = app;
            this.transaction = transaction;

            pending = AppHost.Pipes == null ? 1 : AppHost.Pipes.Count;
            step    = PipelineStep.PreProcess;
            handle  = GCHandle.Alloc(this);

            transaction.Response.OnEnd += HandleEnd;
        }
示例#11
0
        public HttpResponse(IHttpTransaction transaction, SocketStream stream)
        {
            Transaction = transaction;
            Socket      = stream;

            StatusCode = 200;

            WriteHeaders = true;

            Stream         = new HttpStream(this, stream);
            Stream.Chunked = (transaction.Request.MajorVersion > 0 && transaction.Request.MinorVersion > 0);
        }
示例#12
0
        public HttpResponse(IHttpTransaction transaction, SocketStream stream)
        {
            Transaction = transaction;
            Socket = stream;

            StatusCode = 200;

            WriteHeaders = true;

            Stream = new HttpStream (this, stream);
            Stream.Chunked = (transaction.Request.MajorVersion > 0 && transaction.Request.MinorVersion > 0);
        }
示例#13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpRequest"/> class.
        /// </summary>
        /// <param name="source">The source.</param>
        internal HttpRequest(IHttpTransaction source)
        {
            if (source is HttpClient)
                this.client = (HttpClient)source;
            else
                this.connection = (HttpConnection)source;

            this.headers = new HttpHeaderCollection();
            this.query = new Dictionary<string, string>();
            this.version = "";
            this.path = "";
        }
示例#14
0
        public void HandleTransaction(ManosApp app, IHttpTransaction con)
        {
            bool end = false;

            if (con == null)
                throw new ArgumentNullException ("con");

            OnPreProcessRequest (this, con);
            if (con.Aborted)
                goto cleanup;

            var ctx = new ManosContext (con);

            var handler = OnPreProcessTarget (ctx);
            if (handler == null)
                handler = Routes.Find (con.Request);

            if (handler == null) {
                Console.WriteLine ("no handler found for: '{0}'", ctx.Request.LocalPath);
                con.Response.StatusCode = 404;
                con.Response.End ();
                return;
            }

            con.Response.StatusCode = 200;

            OnPostProcessTarget (ctx, handler);

            try {
                handler.Invoke (app, new ManosContext (con));
            } catch (Exception e) {
                Console.Error.WriteLine ("Exception in transaction handler:");
                Console.Error.WriteLine (e);
                con.Response.StatusCode = 500;
                //
                // TODO: Maybe the cleanest thing to do is
                // have a HandleError, HandleException thing
                // on HttpTransaction, along with an UnhandledException
                // method/event on ManosModule.
                //
                end = true;
            }

            if (con.Response.StatusCode == 404)
                con.Response.End ();

            cleanup:
            OnPostProcessRequest (this, con);

            if (end)
                con.Response.End ();
        }
示例#15
0
        public HttpResponse(IHttpTransaction transaction, Encoding encoding)
        {
            Transaction = transaction;
            Encoding = encoding;

            StatusCode = 200;

            WriteHeaders = true;
            WriteStatusLine = true;

            Headers = new HttpHeaders ();
            SetStandardHeaders ();
        }
示例#16
0
        public HttpResponse(IHttpTransaction transaction)
        {
            Transaction = transaction;

            StatusCode = 200;

            WriteHeaders = true;

            Headers = new HttpHeaders ();
            Stream = new HttpResponseStream ();
            Writer = new StreamWriter (Stream);
            Cookies = new Dictionary<string, HttpCookie> ();

            SetStandardHeaders ();
        }
示例#17
0
        public HttpResponse(IHttpTransaction transaction, IOStream stream)
        {
            Transaction = transaction;
            IOStream = stream;

            StatusCode = 200;

            WriteHeaders = true;

            Headers = new HttpHeaders ();
            Stream = new HttpResponseStream (this, IOStream);
            Stream.Chunked = (transaction.Request.MajorVersion > 0 && transaction.Request.MinorVersion > 0);

            end_watcher = new AsyncWatcher (IOLoop.Instance.EventLoop, OnEnd);
            end_watcher.Start ();
        }
示例#18
0
        public HttpResponse(IHttpTransaction transaction, Encoding encoding)
        {
            Transaction = transaction;
            Encoding = encoding;

            StatusCode = 200;

            WriteHeaders = true;
            WriteStatusLine = true;

            Headers = new HttpHeaders ();
            Stream = new HttpResponseStream ();
            Cookies = new Dictionary<string, HttpCookie> ();

            SetStandardHeaders ();
        }
示例#19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpRequest"/> class.
        /// </summary>
        /// <param name="source">The source.</param>
        internal HttpRequest(IHttpTransaction source)
        {
            if (source is HttpClient)
            {
                this.client = (HttpClient)source;
            }
            else
            {
                this.connection = (HttpConnection)source;
            }

            this.headers = new HttpHeaderCollection();
            this.query   = new Dictionary <string, string>();
            this.version = "";
            this.path    = "";
        }
示例#20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpResponse"/> class.
        /// </summary>
        /// <param name="source">The source.</param>
        internal HttpResponse(IHttpTransaction source)
        {
            if (source is HttpClient)
                this.client = (HttpClient)source;
            else
                this.connection = (HttpConnection)source;

            this.status = HttpStatus.OK;
            this.buffer = new MemoryStream();
            this.headers = new HttpHeaderCollection();

            if (source is HttpConnection) {
                headers["Content-Type"] = "text/html";
                headers["X-Frame-Options"] = "deny";
            }
        }
示例#21
0
        public void OnPostProcessRequest(ManosApp app, IHttpTransaction transaction)
        {
            if (AppHost.Pipes == null)
            {
                return;
            }

            foreach (IManosPipe pipe in AppHost.Pipes)
            {
                try {
                    pipe.OnPostProcessRequest(this, transaction);
                } catch (Exception e) {
                    Console.Error.WriteLine("Exception in {0}::OnPostProcessRequest.", pipe);
                    Console.Error.WriteLine(e);
                }
            }
        }
示例#22
0
        public HttpRequest(IHttpTransaction transaction, HttpHeaders headers, string method, string resource, bool support_1_1)
        {
            Transaction = transaction;
            Headers = headers;
            Method = method;
            ResourceUri = resource;
            Http_1_1_Supported = support_1_1;

            Data = new DataDictionary ();
            UriData = new DataDictionary ();
            QueryData = new DataDictionary ();
            PostData = new DataDictionary ();

            Data.Children.Add (UriData);
            Data.Children.Add (QueryData);
            Data.Children.Add (PostData);

            SetEncoding ();
            SetPathAndQuery ();
        }
示例#23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpResponse"/> class.
        /// </summary>
        /// <param name="source">The source.</param>
        internal HttpResponse(IHttpTransaction source)
        {
            if (source is HttpClient)
            {
                this.client = (HttpClient)source;
            }
            else
            {
                this.connection = (HttpConnection)source;
            }

            this.status  = HttpStatus.OK;
            this.buffer  = new MemoryStream();
            this.headers = new HttpHeaderCollection();

            if (source is HttpConnection)
            {
                headers["Content-Type"]    = "text/html";
                headers["X-Frame-Options"] = "deny";
            }
        }
示例#24
0
        public override void OnPostProcessRequest(ManosApp app, IHttpTransaction transaction)
        {
            // LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
            // %h - Remote host       -- DONT HAVE
            // %l - Remote log name   -- DONT HAVE
            // %u - Remote user       -- DONT HAVE
            // %t - Date+Time
            // %r - Request path
            // %s - Status Code
            // %b - Bytes sent
            // %Referer -
            // %User Agent -

            string line = String.Format ("- - - [{0}] \"{1}\" {2} {3} - -\n",
                    DateTime.Now.ToString ("dd/MMM/yyyy:HH:mm:ss K"),
                    transaction.Request.Path,
                    transaction.Response.StatusCode,
                    transaction.Response.Headers.ContentLength);

            byte [] data = Encoding.Default.GetBytes (line);
            stream.BeginWrite (data, 0, data.Length, null, null);
        }
示例#25
0
        public override void OnPostProcessRequest(ManosApp app, IHttpTransaction transaction)
        {
            // LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
            // %h - Remote host       -- DONT HAVE
            // %l - Remote log name   -- DONT HAVE
            // %u - Remote user       -- DONT HAVE
            // %t - Date+Time
            // %r - Request path
            // %s - Status Code
            // %b - Bytes sent
            // %Referer -
            // %User Agent -

            string line = String.Format("- - - [{0}] \"{1}\" {2} {3} - -\n",
                                        DateTime.Now.ToString("dd/MMM/yyyy:HH:mm:ss K"),
                                        transaction.Request.Path,
                                        transaction.Response.StatusCode,
                                        transaction.Response.Headers.ContentLength);

            byte [] data = Encoding.Default.GetBytes(line);
            stream.BeginWrite(data, 0, data.Length, null, null);
        }
示例#26
0
        public void HandleTransaction(ManosApp app, IHttpTransaction con)
        {
            Pipeline pipeline = new Pipeline (app, con);

            pipeline.Begin ();
        }
示例#27
0
 public virtual void OnPostProcessRequest(ManosApp app, IHttpTransaction transaction, Action complete)
 {
     complete();
 }
示例#28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpFormatException"/> class.
 /// </summary>
 /// <param name="transaction">The transaction.</param>
 public HttpFormatException(IHttpTransaction transaction)
     : base()
 {
     this.transaction = transaction;
 }
示例#29
0
        public void HandleTransaction(ManosApp app, IHttpTransaction con)
        {
            bool end = false;

            if (con == null)
            {
                throw new ArgumentNullException("con");
            }

            OnPreProcessRequest(this, con);
            if (con.Aborted)
            {
                goto cleanup;
            }

            var ctx = new ManosContext(con);

            var handler = OnPreProcessTarget(ctx);

            if (handler == null)
            {
                handler = Routes.Find(con.Request);
            }

            if (handler == null)
            {
                Console.WriteLine("no handler found for: '{0}'", ctx.Request.Path);
                con.Response.StatusCode = 404;
                con.Response.End();
                return;
            }

            con.Response.StatusCode = 200;

            OnPostProcessTarget(ctx, handler);

            try {
                handler.Invoke(app, new ManosContext(con));
            } catch (Exception e) {
                Console.Error.WriteLine("Exception in transaction handler:");
                Console.Error.WriteLine(e);
                con.Response.StatusCode = 500;
                //
                // TODO: Maybe the cleanest thing to do is
                // have a HandleError, HandleException thing
                // on HttpTransaction, along with an UnhandledException
                // method/event on ManosModule.
                //
                end = true;
            }

            if (con.Response.StatusCode == 404)
            {
                con.Response.End();
            }

cleanup:
            OnPostProcessRequest(this, con);

            if (end)
            {
                con.Response.End();
            }
        }
示例#30
0
 public ManosContext(IHttpTransaction transaction)
 {
     Transaction = transaction;
 }
示例#31
0
        public void OnPreProcessRequest(ManosApp app, IHttpTransaction transaction)
        {
            if (AppHost.Pipes == null)
                return;

            foreach (IManosPipe pipe in AppHost.Pipes) {
                try {
                    pipe.OnPreProcessRequest (app, transaction);

                    if (transaction.Aborted)
                        return;

                } catch (Exception e) {
                    Console.Error.WriteLine ("Exception in {0}::OnPreProcessRequest.", pipe);
                    Console.Error.WriteLine (e);
                }
            }
        }
示例#32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpFormatException"/> class.
 /// </summary>
 /// <param name="transaction">The transaction.</param>
 public HttpFormatException(IHttpTransaction transaction)
     : base()
 {
     this.transaction = transaction;
 }
示例#33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpReader"/> class.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="transaction">The transaction.</param>
 public HttpReader(Stream stream, IHttpTransaction transaction)
 {
     this.reader      = new StreamReader(stream);
     this.transaction = transaction;
 }
示例#34
0
文件: AppHost.cs 项目: restrepo/manos
 public static void HandleTransaction(IHttpTransaction con)
 {
     app.HandleTransaction (app, con);
 }
示例#35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpWriter"/> class with the provided stream.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="transaction">The transaction.</param>
 public HttpWriter(Stream stream, IHttpTransaction transaction)
 {
     this.writer = new StreamWriter(stream);
     this.transaction = transaction;
 }
示例#36
0
 public virtual void OnPreProcessRequest(ManosApp app, IHttpTransaction transaction, Action complete)
 {
     complete ();
 }
示例#37
0
 public virtual void OnPreProcessRequest(ManosApp app, IHttpTransaction transaction)
 {
 }
示例#38
0
 public static void HandleTransaction(IHttpTransaction con)
 {
     app.HandleTransaction(app, con);
 }
示例#39
0
 public MockHttpResponse(IHttpTransaction txn)
 {
     this.Headers = new HttpHeaders ();
     this.Transaction = txn;
 }
示例#40
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpFormatException"/> class.
 /// </summary>
 /// <param name="transaction">The transaction.</param>
 /// <param name="message">The message.</param>
 /// <param name="innerException">The inner exception.</param>
 public HttpFormatException(IHttpTransaction transaction, string message, Exception innerException)
     : base(message, innerException)
 {
     this.transaction = transaction;
 }
示例#41
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpWriter"/> class with the provided stream.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="transaction">The transaction.</param>
 public HttpWriter(Stream stream, IHttpTransaction transaction)
 {
     this.writer      = new StreamWriter(stream);
     this.transaction = transaction;
 }
示例#42
0
        public void HandleTransaction(ManosApp app, IHttpTransaction con)
        {
            Pipeline pipeline = new Pipeline(app, con);

            pipeline.Begin();
        }
示例#43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpReader"/> class.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="transaction">The transaction.</param>
 public HttpReader(Stream stream, IHttpTransaction transaction)
 {
     this.reader = new StreamReader(stream);
     this.transaction = transaction;
 }
示例#44
0
 public virtual void OnPostProcessRequest(ManosApp app, IHttpTransaction transaction)
 {
 }
示例#45
0
 public MockHttpResponse(IHttpTransaction txn)
 {
     this.Headers     = new HttpHeaders();
     this.Transaction = txn;
 }
示例#46
0
 public static void HandleTransaction(IHttpTransaction con)
 {
     try {
         Log.Debug ("HandleTransaction: START ({0}) \"{1}\"", con.Request.Socket.RemoteEndpoint.ToString(), con.Request.Path);
         app.HandleTransaction (app, con);
         Log.Debug ("HandleTransaction: END ({0}) \"{1}\"", con.Request.Socket.RemoteEndpoint.ToString(), con.Request.Path);
     } catch (Exception ex) {
         Log.Debug ("HandleTransactionException: {0}", ex);
     }
 }
示例#47
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpFormatException"/> class.
 /// </summary>
 /// <param name="transaction">The transaction.</param>
 /// <param name="message">The message.</param>
 /// <param name="innerException">The inner exception.</param>
 public HttpFormatException(IHttpTransaction transaction, string message, Exception innerException)
     : base(message, innerException)
 {
     this.transaction = transaction;
 }
示例#48
0
 public ManosContext(IHttpTransaction transaction)
 {
     Transaction = transaction;
 }