상속: IDisposable
예제 #1
0
        public HttpTransaction(HttpServer server, Socket socket, HttpConnectionCallback callback, bool closeOnEnd = false)
        {
            Server = server;
            Socket = socket;
            this.closeOnEnd = closeOnEnd;

            ConnectionCallback = callback;

            gc_handle = GCHandle.Alloc (this);

            Request = new HttpRequest (this, socket);
            Request.Read (Close);
        }
예제 #2
0
        public HttpTransaction(HttpServer server, IOStream stream, Socket socket, HttpConnectionCallback callback)
        {
            Server = server;
            IOStream = stream;
            Socket = socket;
            ConnectionCallback = callback;

            stream.OnClose (OnClose);

            parser_settings = CreateParserSettings ();
            parser = new HttpParser ();

            stream.ReadBytes (OnBytesRead);
        }
예제 #3
0
        public HttpTransaction(HttpServer server, SocketStream stream, HttpConnectionCallback callback)
        {
            Server = server;
            Stream = stream;

            ConnectionCallback = callback;

            gc_handle = GCHandle.Alloc (this);

            Stream.Closed += delegate (object sender, EventArgs args) {
                Close ();
            };

            Request = new HttpRequest (this, stream);
            Request.Read ();
        }
예제 #4
0
        public static HttpTransaction BeginTransaction(HttpServer server, SocketStream stream, HttpConnectionCallback cb)
        {
            HttpTransaction transaction = new HttpTransaction (server, stream, cb);

            return transaction;
        }
예제 #5
0
파일: Server.cs 프로젝트: kevinswiber/gate
        public static IDisposable Create(AppDelegate app, int port, string path)
        {
            app = ErrorPage.Middleware(app);

            var effectivePath = path;

            var endpoint = new IPEndPoint(IPAddress.Any, port);
            var context = Context.Create();
            var httpServer = new HttpServer(
                context,
                transaction =>
                {
                    var cts = new CancellationTokenSource();

                    var requestPathBase = effectivePath;
                    if (requestPathBase == "/" || requestPathBase == null)
                        requestPathBase = "";

                    var requestPath = transaction.Request.Path;
                    if (requestPath.StartsWith(requestPathBase, StringComparison.OrdinalIgnoreCase))
                        requestPath = requestPath.Substring(requestPathBase.Length);

                    var requestQueryString = RequestQueryString(transaction.Request.QueryData);

                    var requestHeaders = transaction.Request.Headers.Keys.ToDictionary(k => k, k => transaction.Request.Headers[k], StringComparer.OrdinalIgnoreCase);
                    var env = new Dictionary<string, object>
                    {
                        {OwinConstants.Version, "1.0"},
                        {OwinConstants.RequestMethod, transaction.Request.Method.ToString().Substring(5)},
                        {OwinConstants.RequestScheme, "http"},
                        {OwinConstants.RequestPathBase, requestPathBase},
                        {OwinConstants.RequestPath, requestPath},
                        {OwinConstants.RequestQueryString, requestQueryString},
                        {OwinConstants.RequestHeaders, requestHeaders},
                        {OwinConstants.RequestBody, RequestBody(transaction.Request.PostBody, transaction.Request.ContentEncoding)},
                        {"Manos.Http.IHttpTransaction", transaction},
                        {"server.CLIENT_IP", transaction.Request.Socket.RemoteEndpoint.Address.ToString()},
                        {"System.Threading.CancellationToken", cts.Token}
                    };

                    app(
                        env,
                        (status, headers, body) =>
                        {
                            transaction.Response.StatusCode = int.Parse(status.Substring(0, 3));
                            foreach (var header in headers)
                            {
                                if (string.Equals(header.Key, "Set-Cookie", StringComparison.OrdinalIgnoreCase))
                                {
                                    // use a header-injection to avoid re-parsing values into Manos HttpCookie structure
                                    transaction.Response.SetHeader(header.Key, string.Join("\r\nSet-Cookie: ", header.Value.ToArray()));
                                }
                                else
                                {
                                    transaction.Response.SetHeader(header.Key, string.Join(",", header.Value.ToArray()));
                                }
                            }

                            body(
                                data =>
                                {
                                    var duplicate = new byte[data.Count];
                                    Array.Copy(data.Array, data.Offset, duplicate, 0, data.Count);
                                    transaction.Response.Write(duplicate);
                                    return false;
                                },
                                _ => false,
                                ex => transaction.Response.End(),
                                cts.Token);
                        },
                        ex =>
                        {
                            // This should never be called
                            throw new NotImplementedException();
                        });
                },
                context.CreateTcpServerSocket(endpoint.AddressFamily),
                true);
            httpServer.Listen(endpoint.Address.ToString(), port);

            var thread = new Thread(context.Start);
            thread.Start();

            return new Disposable(() =>
            {
                context.Stop();
                thread.Join(250);
                //httpServer.Dispose();
            });
        }
예제 #6
0
파일: AppHost.cs 프로젝트: restrepo/manos
        public static void Start(ManosApp application)
        {
            if (application == null)
                throw new ArgumentNullException ("application");

            app = application;

            app.StartInternal ();

            started = true;

            foreach (var ep in listenEndPoints) {

                var server = new HttpServer (IOLoop, HandleTransaction, IOLoop.CreateSocket());
                server.Listen (ep.Address.ToString (), ep.Port);

                servers.Add (server);
            }
            foreach (var ep in secureListenEndPoints.Keys) {
                var keypair = secureListenEndPoints [ep];
                var socket = IOLoop.CreateSecureSocket (keypair.Item1, keypair.Item2);
                var server = new HttpServer (ioloop, HandleTransaction, socket);
                server.Listen (ep.Address.ToString (), ep.Port);

                servers.Add (server);
            }

            ioloop.Start ();
        }
예제 #7
0
        public static HttpTransaction BeginTransaction(HttpServer server, ISocketStream stream, HttpConnectionCallback cb, bool closeOnEnd = false)
        {
            HttpTransaction transaction = new HttpTransaction (server, stream, cb, closeOnEnd);

            return transaction;
        }
예제 #8
0
파일: AppHost.cs 프로젝트: headsling/manos
        public static void Start(ManosApp application)
        {
            if (application == null)
                throw new ArgumentNullException ("application");

            app = application;

            started = true;
            server = new HttpServer (HandleTransaction, ioloop);

            server.Listen (IPAddress.ToString (), port);

            ioloop.Start ();
        }
예제 #9
0
        public static void Start(ManosApp application)
        {
            if (application == null)
                throw new ArgumentNullException ("application");

            app = application;

            started = true;
            server = new HttpServer (HandleTransaction, ioloop);

            IPEndPoint endpoint = new IPEndPoint (IPAddress, port);

            Server.Bind (endpoint);

            server.Start ();
            ioloop.Start ();
        }
예제 #10
0
        public static HttpTransaction BeginTransaction(HttpServer server, SocketStream stream, HttpConnectionCallback cb, bool closeOnEnd = false)
        {
            HttpTransaction transaction = new HttpTransaction(server, stream, cb, closeOnEnd);

            return(transaction);
        }
예제 #11
0
        public static HttpTransaction BeginTransaction(HttpServer server, SocketStream stream, HttpConnectionCallback cb)
        {
            HttpTransaction transaction = new HttpTransaction(server, stream, cb);

            return(transaction);
        }
예제 #12
0
파일: AppHost.cs 프로젝트: Hyperfair/manos
        public static void Initialize(ManosApp application)
        {
            if (application == null)
                throw new ArgumentNullException ("application");

            app = application;

            app.StartInternal ();

            foreach (var ep in listenEndPoints) {
                var server = new HttpServer (Context, HandleTransaction, Context.CreateTcpServerSocket (ep.AddressFamily));
                server.Listen (ep.Address.ToString (), ep.Port);

                servers.Add (server);
            }
            foreach (var ep in secureListenEndPoints.Keys) {
            //				var keypair = secureListenEndPoints [ep];
            //				var socket = Context.CreateSecureSocket (keypair.Item1, keypair.Item2);
            //				var server = new HttpServer (context, HandleTransaction, socket);
            //				server.Listen (ep.Address.ToString (), ep.Port);
            //
            //				servers.Add (server);
            }
        }
예제 #13
0
        public static HttpTransaction BeginTransaction(HttpServer server, ITcpSocket socket, HttpConnectionCallback cb,
                                                       bool closeOnEnd = false)
        {
            var transaction = new HttpTransaction(server, socket, cb, closeOnEnd);

            return transaction;
        }