private void OnGetContext(object ctx) { if (shutdownInProgress) { return; } try { var context = (HttpListenerContext)ctx; var conn = new Connection(this, context); if (!Thread.CurrentThread.CurrentCulture.Equals(currentThreadCulture)) { Thread.CurrentThread.CurrentCulture = currentThreadCulture; Thread.CurrentThread.CurrentUICulture = currentThreadCulture; } if (conn.WaitForRequestBytes() == 0) { conn.WriteErrorAndClose(400); } else { var host = GetHost(); if (host == null) { conn.WriteErrorAndClose(500); } else { var handlerContext = new HttpHandlerContext(this, host, conn, Thread.CurrentPrincipal.Identity); HttpHandlerFactory.GetHttpHandler(handlerContext) .ProcessRequest(handlerContext); } } } catch (Exception ex) { log.Warn(ServerMessages.ExceptionWhileProcessing, ex); } }
private void ParseRequestLine() { ByteString[] strArray = ((ByteString)_headerByteStrings[0]).Split(' '); if (((strArray == null) || (strArray.Length < 2)) || (strArray.Length > 3)) { _connection.WriteErrorAndClose(400); } else { _verb = strArray[0].GetString(); ByteString str2 = strArray[1]; _url = str2.GetString(); _prot = strArray.Length == 3 ? strArray[2].GetString() : "HTTP/1.0"; int index = str2.IndexOf('?'); _queryStringBytes = index > 0 ? str2.Substring(index + 1).GetBytes() : new byte[0]; index = _url.IndexOf('?'); if (index > 0) { _path = _url.Substring(0, index); _queryString = _url.Substring(index + 1); } else { _path = _url; _queryStringBytes = new byte[0]; } if (_path.IndexOf('%') >= 0) { _path = HttpUtility.UrlDecode(_path, Encoding.UTF8); index = _url.IndexOf('?'); if (index >= 0) { _url = _path + _url.Substring(index); } else { _url = _path; } } int startIndex = _path.LastIndexOf('.'); int num3 = _path.LastIndexOf('/'); if (((startIndex >= 0) && (num3 >= 0)) && (startIndex < num3)) { int length = _path.IndexOf('/', startIndex); _filePath = _path.Substring(0, length); _pathInfo = _path.Substring(length); } else { _filePath = _path; _pathInfo = string.Empty; } _path = _path.Replace("//", "/"); _filePath = _filePath.Replace("//", "/"); // Fix of // file _pathTranslated = MapPath(_filePath); } }