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(HandleTransaction, ioloop); server.Listen(ep.Address.ToString(), ep.Port); servers.Add(server); } syncBlockWatcher = new AsyncWatcher(IOLoop.EventLoop, HandleSynchronizationEvent); syncBlockWatcher.Start(); ioloop.Start(); }
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(HandleTransaction, IOLoop.CreateSocketStream()); 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(HandleTransaction, socket); server.Listen(ep.Address.ToString(), ep.Port); servers.Add(server); } ioloop.Start(); }
public override void OnPreProcessRequest(ManosApp app, Manos.Http.IHttpTransaction transaction, Action complete) { transaction.Response.ContentEncoding = Encoding.UTF8; //transaction.Response.Headers.SetHeader("Content-Type", "text/plain; charset=UTF-8"); //transaction.Response.Headers.SetHeader("Content-Language", "en"); transaction.Response.Headers.ContentEncoding = Encoding.UTF8; complete(); }
/// <summary> /// Causes the action specified in the constructor to be executed. Infrastructure. /// </summary> /// <param name="app"> /// A <see cref="ManosApp"/> /// </param> public void Run(ManosApp app) { try { callback (app, data); } catch (Exception e) { Console.Error.WriteLine ("Exception in timeout callback."); Console.Error.WriteLine (e); } repeat.RepeatPerformed (); }
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; }
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); } } }
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; }
/// <summary> /// Causes the action specified in the constructor to be executed. Infrastructure. /// </summary> /// <param name="app"> /// A <see cref="ManosApp"/> /// </param> public void Run(ManosApp app) { try { callback(app, data); } catch (Exception e) { Console.Error.WriteLine("Exception in timeout callback."); Console.Error.WriteLine(e); } repeat.RepeatPerformed(); }
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 (); }
/// <summary> /// Causes the action specified in the constructor to be executed. Infrastructure. /// </summary> /// <param name="app"> /// A <see cref="ManosApp"/> /// </param> public void Run(ManosApp app) { // With very short timers, it's possible two or more events could be queued before RepeatPerformed() below gets called // so double check we're not firing too many times if (!ShouldContinueToRepeat()) return; try { callback (app, data); } catch (Exception e) { Console.Error.WriteLine ("Exception in timeout callback."); Console.Error.WriteLine (e); } repeat.RepeatPerformed (); }
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(); }
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); } } }
public static void Start(ManosApp application) { if (application == null) { throw new ArgumentNullException("application"); } app = application; app.StartInternal(); started = true; server = new HttpServer(HandleTransaction, ioloop); server.Listen(IPAddress.ToString(), port); syncBlockWatcher = new AsyncWatcher(IOLoop.EventLoop, HandleSynchronizationEvent); syncBlockWatcher.Start(); ioloop.Start(); }
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); }
// Load configuration from file // Search path: // 1.<app_folder>/manos.config // TODO: because execution of config scripts is async, we can run into race conditions if application // code requests a config variable before we're done executing the script. We should add a callback // parameter, so we can notify the ManosApp that config is ready for business. public static void Load(ManosApp app) { #if ENABLE_CONFIG Evaluator.Init(new string[0]); string [] sources = { Path.Combine(Environment.CurrentDirectory, "manos.config"), }; foreach (string src in sources) { try { if (File.Exists(src)) { AsyncParseWorker w = new AsyncParseWorker(ParseFile); w.BeginInvoke(src, ir => { AsyncResult res = (AsyncResult)ir; AsyncParseWorker cw = (AsyncParseWorker)res.AsyncDelegate; cw.EndInvoke(ir); }, null); } } catch (Exception ex) { AppHost.Log.Error("Error processing configuration: {0}", ex.Message); AppHost.Log.Error("Trace: {0}", ex.StackTrace); continue; } } #endif }
public void HandleTransaction(ManosApp app, IHttpTransaction con) { Pipeline pipeline = new Pipeline (app, con); pipeline.Begin (); }
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); } }
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(); } }
private void DoSetUser(ManosApp app, object user_data) { #if DISABLE_POSIX throw new InvalidOperationException ("Attempt to set user on a non-posix build."); #else string user = user_data as string; Console.WriteLine ("setting user to: '{0}'", user); if (user == null) { AppHost.Stop (); throw new InvalidOperationException (String.Format ("Attempting to set user to null.")); } Passwd pwd = Syscall.getpwnam (user); if (pwd == null) { AppHost.Stop (); throw new InvalidOperationException (String.Format ("Unable to find user '{0}'.", user)); } int error = Syscall.seteuid (pwd.pw_uid); if (error != 0) { AppHost.Stop (); throw new InvalidOperationException (String.Format ("Unable to switch to user '{0}' error: '{1}'.", user, error)); } #endif }
public virtual void OnPostProcessRequest(ManosApp app, IHttpTransaction transaction) { }
public void Run() { app = LoadLibrary (ApplicationAssembly); Console.WriteLine ("Running {0} on port {1}.", app, Port); AppHost.Start (app); }
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 (); }
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); } } }
public static void Start(ManosApp application) { started = true; context.Start (); }
private static void DoBrowse(ManosApp app, object user_data) { string BrowseTo = user_data as string; Console.WriteLine("Launching {0}", BrowseTo); System.Diagnostics.Process.Start(BrowseTo); }
public virtual void OnPreProcessRequest(ManosApp app, IHttpTransaction transaction) { }
public void HandleTransaction(ManosApp app, IHttpTransaction con) { Pipeline pipeline = new Pipeline(app, con); pipeline.Begin(); }
void StartServer() { if (app == null) app = LoadLibrary(ApplicationAssembly); _statusLabel.Text = "Started on port " + _port.Value; var listenAddress = System.Net.IPAddress.Any; AppHost.ListenAt(new System.Net.IPEndPoint(listenAddress, _port.Value)); _thread = new Thread(new ThreadStart(delegate { Console.WriteLine("Before Start!"); AppHost.Start(app); Console.WriteLine("Duh"); })); _thread.IsBackground = true; _thread.Start(); }
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 (); }
public virtual void OnPostProcessRequest(ManosApp app, IHttpTransaction transaction, Action complete) { complete(); }
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 (); }
public ManosApp LoadLibrary(string library) { Assembly a = Assembly.LoadFrom (library); foreach (Type t in a.GetTypes ()) { if (t.BaseType == typeof (ManosApp)) { if (app != null) throw new Exception ("Library contains multiple apps."); app = CreateAppInstance (t); } } return app; }
public void Run() { app = LoadLibrary (ApplicationAssembly); Console.WriteLine ("Running {0} on port {1}.", app, Port); if (User != null) SetServerUser (User); if (IPAddress != null) AppHost.IPAddress = System.Net.IPAddress.Parse (IPAddress); AppHost.Port = Port; AppHost.Start (app); }
public void Run() { // Load the config. ManosConfig.Load (); app = Loader.LoadLibrary<ManosApp> (ApplicationAssembly, Arguments); Console.WriteLine ("Running {0} on port {1}.", app, Port); if (User != null) SetServerUser (User); var listenAddress = System.Net.IPAddress.Any; if (IPAddress != null) listenAddress = System.Net.IPAddress.Parse (IPAddress); AppHost.ListenAt (new System.Net.IPEndPoint (listenAddress, Port)); if (SecurePort != null) { AppHost.InitializeTLS ("NORMAL"); AppHost.SecureListenAt (new System.Net.IPEndPoint (listenAddress, SecurePort.Value), CertificateFile, KeyFile); Console.WriteLine ("Running {0} on secure port {1}.", app, SecurePort); } AppHost.Start (app); }
public virtual void OnPreProcessRequest(ManosApp app, IHttpTransaction transaction, Action complete) { complete (); }
public void Run() { // Setup the document root if (DocumentRoot != null) { System.IO.Directory.SetCurrentDirectory(System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), DocumentRoot)); } // Load the config. ManosConfig.Load (); AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolve); app = Loader.LoadLibrary<ManosApp> (ApplicationAssembly, Arguments); Console.WriteLine ("Running {0} on port {1}.", app, Port); if (User != null) SetServerUser (User); var listenAddress = System.Net.IPAddress.Any; if (IPAddress != null) listenAddress = System.Net.IPAddress.Parse (IPAddress); AppHost.ListenAt (new System.Net.IPEndPoint (listenAddress, Port)); if (SecurePort != null) { AppHost.InitializeTLS ("NORMAL"); AppHost.SecureListenAt (new System.Net.IPEndPoint (listenAddress, SecurePort.Value), CertificateFile, KeyFile); Console.WriteLine ("Running {0} on secure port {1}.", app, SecurePort); } if (Browse != null) { var hostname = IPAddress == null ? "http://localhost" : "http://" + IPAddress; if (Port != 80) hostname += ":" + Port.ToString(); if (Browse == "") { Browse = hostname; } if (Browse.StartsWith("/")) { Browse = hostname + Browse; } if (!Browse.StartsWith("http://") && !Browse.StartsWith("https://")) Browse = "http://" + Browse; AppHost.AddTimeout(TimeSpan.FromMilliseconds(10), RepeatBehavior.Single, Browse, DoBrowse); } AppHost.Start (app); }
public void Run() { // Load the config. ManosConfig.Load (); app = Loader.LoadLibrary<ManosApp> (ApplicationAssembly, Arguments); Console.WriteLine ("Running {0} on port {1}.", app, Port); if (User != null) SetServerUser (User); if (IPAddress != null) AppHost.IPAddress = System.Net.IPAddress.Parse (IPAddress); AppHost.Port = Port; AppHost.Start (app); }