private void OnSocketAccept(object acceptedSocket) { if (!_shutdownInProgress) { Connection conn = new Connection(this, (Socket)acceptedSocket); // wait for at least some input if (conn.WaitForRequestBytes() == 0) { conn.WriteErrorAndClose(400); return; } // find or create host Host host = GetHost(); if (host == null) { conn.WriteErrorAndClose(500); return; } // process request in worker app domain host.ProcessRequest(conn); } }
public void Process() { // read the request if (!TryParseRequest()) { return; } // 100 response to POST if (_verb == "POST" && _contentLength > 0 && _preloadedContentLength < _contentLength) { _connection.Write100Continue(); } // special case for client script if (_isClientScriptPath) { _connection.WriteEntireResponseFromFile(_host.PhysicalClientScriptPath + _path.Substring(_host.NormalizedClientScriptPath.Length), false); return; } // deny access to code, bin, etc. if (IsRequestForRestrictedDirectory()) { _connection.WriteErrorAndClose(403); return; } // special case for a request to a directory (ensure / at the end and process default documents) if (ProcessDirectoryRequest()) { return; } PrepareResponse(); // Hand the processing over to HttpRuntime HttpRuntime.ProcessRequest(this); }
public void Process() { ReadAllHeaders(); if (_headerBytes == null || _endHeadersOffset < 0 || _headerByteStrings == null || _headerByteStrings.Count == 0) { _conn.WriteErrorAndClose(400); return; } ParseRequestLine(); // Check for bad path if (IsBadPath()) { _conn.WriteErrorAndClose(400); return; } // Check if the path is not well formed or is not for the current app bool isClientScriptPath = false; String clientScript = null; if (!_host.IsVirtualPathInApp(_path, out isClientScriptPath, out clientScript)) { _conn.WriteErrorAndClose(404); return; } ParseHeaders(); ParsePostedContent(); if (_verb == "POST" && _contentLength > 0 && _preloadedContentLength < _contentLength) { _conn.Write100Continue(); } // special case for client script if (isClientScriptPath) { _conn.WriteEntireResponseFromFile(_host.PhysicalClientScriptPath + clientScript, false); return; } // special case for directory listing if (ProcessDirectoryListingRequest()) { return; } PrepareResponse(); // Hand the processing over to HttpRuntime HttpRuntime.ProcessRequest(this); }
public void Start() { _IsShutdownInProgress = false; try { _Socket = CreateSocketBindAndListen(AddressFamily.InterNetwork, IPAddress.Loopback, Website.Port); } catch (Exception e) { _Socket = CreateSocketBindAndListen(AddressFamily.InterNetworkV6, IPAddress.IPv6Loopback, Website.Port); } Task.Factory.StartNew(() => { while (!_IsShutdownInProgress) { try { var acceptedSocket = _Socket.Accept(); Task.Factory.StartNew(() => { if (!_IsShutdownInProgress) { var conn = new Connection(this, acceptedSocket); // wait for at least some input if (conn.WaitForRequestBytes() == 0) { conn.WriteErrorAndClose(400); return; } // find or create host var host = GetHost(); if (host == null) { conn.WriteErrorAndClose(500); return; } // process request in worker app domain host.ProcessRequest(conn); } }); } catch { Thread.Sleep(100); } } }); }
/// <summary> /// /// </summary> public void Start() { _socket = CreateSocketBindAndListen(AddressFamily.InterNetwork, _ipAddress, _port); //start the timer StartTimer(); ThreadPool.QueueUserWorkItem(delegate { while (!_shutdownInProgress) { try { Socket acceptedSocket = _socket.Accept(); ThreadPool.QueueUserWorkItem(delegate { if (!_shutdownInProgress) { var conn = new Connection(this, acceptedSocket); // wait for at least some input if (conn.WaitForRequestBytes() == 0) { conn.WriteErrorAndClose(400); return; } // find or create host Host host = GetHost(); if (host == null) { conn.WriteErrorAndClose(500); return; } IncrementRequestCount(); // process request in worker app domain host.ProcessRequest(conn); DecrementRequestCount(); } }); } catch { Thread.Sleep(100); } } }); OnServerStarted(new ServerEventArgs(RootUrl)); }
public void Start() { try { _socket = CreateSocketBindAndListen(AddressFamily.InterNetwork, _addressType, _port); } catch { _addressType = (_addressType == IPAddress.Any) ? IPAddress.IPv6Any : IPAddress.IPv6Loopback; _socket = CreateSocketBindAndListen(AddressFamily.InterNetworkV6, _addressType, _port); } ThreadPool.QueueUserWorkItem(delegate { while (!_shutdownInProgress) { try { Socket acceptedSocket = _socket.Accept(); ThreadPool.QueueUserWorkItem(delegate { if (!_shutdownInProgress) { var conn = new Connection(this, acceptedSocket); // wait for at least some input if (conn.WaitForRequestBytes() == 0) { conn.WriteErrorAndClose(400); return; } // find or create host Host host = GetHost(); if (host == null) { conn.WriteErrorAndClose(500); return; } // process request in worker app domain host.ProcessRequest(conn); } }); } catch { Thread.Sleep(100); } } }); }
public void Start() { ThreadPool.QueueUserWorkItem(delegate { while (!_shutdownInProgress) { try { m2net.Request acceptedSocket = _mongrel2Connection.Receive(); ThreadPool.QueueUserWorkItem(delegate { if (!_shutdownInProgress) { var conn = new Connection(this, acceptedSocket); //// wait for at least some input //if (conn.WaitForRequestBytes() == 0) //{ // conn.WriteErrorAndClose(400); // return; //} // find or create host Host host = GetHost(); if (host == null) { conn.WriteErrorAndClose(500); return; } // process request in worker app domain host.ProcessRequest(conn); } }); } catch { Thread.Sleep(100); } } }); }
public void Start() { try { _socket = CreateSocketBindAndListen(AddressFamily.InterNetwork, IPAddress.Loopback, _port); } catch { _socket = CreateSocketBindAndListen(AddressFamily.InterNetworkV6, IPAddress.IPv6Loopback, _port); } ThreadPool.QueueUserWorkItem(delegate { while (!_shutdownInProgress) { try { Socket acceptedSocket = _socket.Accept(); ThreadPool.QueueUserWorkItem(delegate { if (!_shutdownInProgress) { var conn = new Connection(this, acceptedSocket); // wait for at least some input if (conn.WaitForRequestBytes() == 0) { conn.WriteErrorAndClose(400); return; } // find or create host Host host = GetHost(); if (host == null) { conn.WriteErrorAndClose(500); return; } // process request in worker app domain host.ProcessRequest(conn); } }); } catch { Thread.Sleep(100); } } }); }
/// <summary> /// 01/06/10 sky: added RequestInfo construction /// </summary> public void Process() { // read the request if (!TryParseRequest()) { return; } _requestInfo.LocalIP = GetLocalAddress(); _requestInfo.RemoteIP = GetRemoteAddress(); _requestInfo.RemoteName = GetRemoteName(); _requestInfo.Verb = _verb; _requestInfo.Url = _url; _requestInfo.Protocol = _prot; _requestInfo.Path = _path; _requestInfo.FilePath = _filePath; _requestInfo.PathInfo = _pathInfo; _requestInfo.PathTranslated = _pathTranslated; _requestInfo.QueryString = _queryString; _requestInfo.ContentLength = _contentLength; _requestInfo.ResponseStatus = _responseStatus; int userAgentIndex = GetKnownRequestHeaderIndex("User-Agent"); if (userAgentIndex > -1) { _requestInfo.UserAgent = _knownRequestHeaders[userAgentIndex]; } _server.OnRequestBegin(new RequestEventArgs(_requestInfo)); // 100 response to POST if (_verb == "POST" && _contentLength > 0 && _preloadedContentLength < _contentLength) { _connection.Write100Continue(); } // special case for client script if (_isClientScriptPath) { _connection.WriteEntireResponseFromFile(_host.PhysicalClientScriptPath + _path.Substring(_host.NormalizedClientScriptPath.Length), false); return; } // deny access to code, bin, etc. if (IsRequestForRestrictedDirectory()) { _connection.WriteErrorAndClose(403); return; } // special case for a request to a directory (ensure / at the end and process default documents) if (ProcessDirectoryRequest()) { return; } PrepareResponse(); // Hand the processing over to HttpRuntime HttpRuntime.ProcessRequest(this); }
public void Start() { _IsShutdownInProgress = false; try { _Socket = CreateSocketBindAndListen(AddressFamily.InterNetwork, IPAddress.Loopback, Website.Port); } catch(Exception e) { _Socket = CreateSocketBindAndListen(AddressFamily.InterNetworkV6, IPAddress.IPv6Loopback, Website.Port); } Task.Factory.StartNew(() => { while (!_IsShutdownInProgress) { try { var acceptedSocket = _Socket.Accept(); Task.Factory.StartNew(() => { if (!_IsShutdownInProgress) { var conn = new Connection(this, acceptedSocket); // wait for at least some input if (conn.WaitForRequestBytes() == 0) { conn.WriteErrorAndClose(400); return; } // find or create host var host = GetHost(); if (host == null) { conn.WriteErrorAndClose(500); return; } // process request in worker app domain host.ProcessRequest(conn); } }); } catch { Thread.Sleep(100); } } }); }