private static IMicroHttpServer GetServer() { var config = new List <ConfigItem>() { new ConfigItem() { DelegateToExecute = GetStatus, HttpMethod = HttpMethod.GET, Uri = "http://localhost:9999/status/" }, new ConfigItem() { DelegateToExecute = Shutdown, HttpMethod = HttpMethod.GET, Uri = "http://localhost:9999/exit/" } }; var server = new MicroHttpServer(config) { WriteOutputHandler = LogWriter.LogMessage, WriteOutputErrorHandler = LogWriter.LogErrorMessage, BasicAuthentication = true }; return(server); }
public void MicroHttpServer_NoConfigation_returnsError() { var server = new MicroHttpServer(null); var res = server.Start(); Assert.IsFalse(res.Success); server.Stop(); }
private IMicroHttpServer GetServer(bool useBasicAuthentication = false) { var config = new List <ConfigItem>() { new ConfigItem() { DelegateToExecute = DelegateSuccess, HttpMethod = HttpMethod.POST, Uri = url1 }, new ConfigItem() { DelegateToExecute = DelegateError, HttpMethod = HttpMethod.GET, Uri = url2 }, new ConfigItem() { DelegateToExecute = DelegateSuccessAuthenticated, HttpMethod = HttpMethod.GET, Uri = urlSuccessAuthenticated }, new ConfigItem() { DelegateToExecute = DelegateNotAuthenticated, HttpMethod = HttpMethod.GET, Uri = urlNotAuthenticated }, new ConfigItem() { DelegateToExecute = DelegateErrorAuthenticated, HttpMethod = HttpMethod.GET, Uri = urlErrorAuthenticated } }; var server = new MicroHttpServer(config) { WriteOutputHandler = Console.WriteLine, WriteOutputErrorHandler = Console.WriteLine, BasicAuthentication = useBasicAuthentication }; return(server); }
static void Main(string[] args) { ConsoleKeyInfo cki; var loggerFactory = LoggerFactory.Create(builder => { builder .SetMinimumLevel(LogLevel.Debug) .AddFilter("Microsoft", LogLevel.Warning) .AddFilter("System", LogLevel.Warning) .AddConsole(); }); _logger = loggerFactory.CreateLogger <Program>(); _logger.LogInformation("Preparing the MicroWebServer..."); var microWebServer = new MicroHttpServer( requestResponderMethod: ProcessWebRequest, routes: new List <string>() { "hello/" }, host: "localhost", port: 8080, responseType: ResponseTypes.Text, utf8: true, allowedOrigin: "*", logger: _logger ); microWebServer.Start(); while (true) { Console.WriteLine("\nCTRL+C to stop the MicroWebServer and exit."); cki = Console.ReadKey(true); if (cki.Key == ConsoleKey.C) { break; } } }
public WebServerWorker(ILogger logger, int workerId, bool autoStart = false) { _workerId = workerId; _logger = logger; _webServer = new MicroHttpServer( requestResponderMethod: ProcessWebRequest, routes: new List <string>() { "hello/" }, host: "localhost", port: 8080, responseType: ResponseTypes.Text, utf8: true, allowedOrigin: "*", logger: _logger ); if (autoStart) { Start(); } }
static void Main(string[] args) { ArduinoWork.threadHandle(THREAD_MODE.START); MicroHttpServer mhs = new MicroHttpServer(1688, (req) => { string response = ""; if (req.Url != "/favicon.ico") { response = ArduinoWork.SetMode(req.Url); Console.WriteLine(req.Url); } return (new CompactResponse() { Data = Encoding.UTF8.GetBytes(response) }); }); Console.WriteLine("Press any key to stop..."); Console.Read(); ArduinoWork.threadHandle(THREAD_MODE.STOP); mhs.Stop(); }