public static HttpServer CreateServer(IHttpHandler handler) { var openPort = NetworkInformation.FindRandomOpenPort(); var server = new HttpServer(openPort, handler); return server; }
/// <summary> /// Starts this instance of the Stumps server. /// </summary> public void Start() { lock (_syncRoot) { if (_started) { return; } _started = true; // Setup the pipeline HTTP handler var pipeline = new HttpPipelineHandler(); // Setup the Stump HTTP handler _stumpsHandler = new StumpsHandler(_stumpsManager); _stumpsHandler.Enabled = this.StumpsEnabled; pipeline.Add(_stumpsHandler); // Setup the Proxy HTTP handler if (_remoteHttpServer != null) { var proxyHandler = new ProxyHandler(_remoteHttpServer); pipeline.Add(proxyHandler); } else { // Setup the Service Unavailable HTTP handler var stumpNotFoundHandler = new FallbackResponseHandler(_defaultResponse); pipeline.Add(stumpNotFoundHandler); } var scheme = _useHttpsForIncommingConnections ? ServerScheme.Https : ServerScheme.Http; _server = new HttpServer(scheme, _port, pipeline); _server.RequestFinished += ServerRequestFinished; _server.RequestProcessed += ServerRequestProcessed; _server.RequestReceived += ServerRequestStarted; _server.StartListening(); } }
/// <summary> /// Stops this instance of the Stumps server. /// </summary> public void Shutdown() { lock (_syncRoot) { if (!_started) { return; } _started = false; _server.StopListening(); _server.Dispose(); _server = null; } }