public void EmptyResponsePageTest() { Action <IAppBuilder> config = (builder) => { builder.Use(typeof(EmptyResponseApplication)); }; using (var server = new FosSelfHost(config)) { server.Bind(ListenOn, ListenPort); server.Start(true); System.Threading.Thread.Sleep(100); // Make the request and expect the empty response page with 500 status code var browser = new Browser(ListenOn, ListenPort); using (var response = browser.ExecuteRequest("http://localhost/", "GET")) { var emptyResponsePage = new EmptyResponsePage(); //Assert.AreNotEqual(0, response.AppStatusCode); Assert.AreEqual(500, response.HttpStatusCode); Assert.AreEqual(emptyResponsePage.Contents, ReadStream(response.ResponseBody)); } } }
public static void Main(string[] args) { using (FosServer = new FosSelfHost(ConfigureOwin)) { StaticConfiguration.DisableErrorTraces = false; FosServer.Bind(IPAddress.Loopback, Int32.Parse(ConfigurationManager.AppSettings["port"])); // Loopback is forced, as it is not mean to be front-facing server FosServer.Start(false); } }
public static void FastCgi(int port) { var startup = new Startup(); using (var fosServer = new FosSelfHost(startup.Configuration)) { fosServer.Bind(System.Net.IPAddress.Loopback, port); fosServer.Start(false); } }
public Task StartAsync <TContext>(IHttpApplication <TContext> application, CancellationToken cancellationToken) { return(Task.Run(() => { Func <IDictionary <string, object>, Task> appFunc = async env => { var owinFeatures = new OwinFeatureCollection(env); var features = new FeatureCollection(owinFeatures); var owinHttpResponse = features.Get <IHttpResponseFeature>(); features.Set <IHttpResponseFeature>(new NoOnStartingHttpResponseFeature(owinHttpResponse)); var context = application.CreateContext(features); try { await application.ProcessRequestAsync(context); } catch (Exception ex) { application.DisposeContext(context, ex); throw; } application.DisposeContext(context, null); }; // Convert OWIN WebSockets to ASP.NET Core WebSockets appFunc = OwinWebSocketAcceptAdapter.AdaptWebSockets(appFunc); // Wrap this into a middleware handler that Fos can accept Func <IDictionary <string, object>, Func <IDictionary <string, object>, Task>, Task> middlewareHandler = async(env, next) => { await appFunc(env); if (next != null) { await next(env); } }; cgiServer = new FosSelfHost(builder => { builder.Use(middlewareHandler); }); cgiServer.Bind(IPAddress.Loopback, 9000); cgiServer.Start(true); }, cancellationToken)); }
public void StartAndDispose() { int port = 9007; // Let's hope this is not being used.. FosSelfHost server; using (server = new FosSelfHost(app => {})) { server.Bind(System.Net.IPAddress.Loopback, port); server.Start(true); Assert.AreEqual(true, server.IsRunning); } Assert.AreEqual(false, server.IsRunning); }
public void ErrorPageTest() { Action <IAppBuilder> config = (builder) => { builder.Use(typeof(ThrowsExceptionApplication)); }; using (var server = new FosSelfHost(config)) { server.Bind(ListenOn, ListenPort); server.Start(true); //System.Threading.Thread.Sleep(1000000); // Make the request and expect the empty response page with 500 status code var browser = new Browser(ListenOn, ListenPort); var response = browser.ExecuteRequest("http://localhost/", "GET"); //Assert.AreNotEqual(0, response.AppStatusCode); Assert.AreEqual(500, response.HttpStatusCode); Assert.That(ReadStream(response.ResponseBody).Contains("An error occured in the application. On purpose.")); } }
public void StartAndDisposeUnixSocket() { FosSelfHost server; using (server = new FosSelfHost(app => {})) { server.Bind("./.FosTestSocket"); server.Start(true); Assert.AreEqual(true, server.IsRunning); } using (server = new FosSelfHost(app => {})) { server.Bind("./.FosTestSocket"); server.Start(true); Assert.AreEqual(true, server.IsRunning); } Assert.AreEqual(false, server.IsRunning); }