public override void Process(Bamboo.WebServer.HttpRequest request, Bamboo.WebServer.HttpResponse response) { try { this._processor.Process(request, response); } catch (System.Exception exception) { response.Reset(); Error(exception); response.Status = 500; response.Headers.Add("Content-Type", "text/plain"); response.WriteLine(exception.Message); response.WriteLine(""); response.WriteLine(exception.StackTrace); while (exception.InnerException != null) { response.WriteLine(""); response.WriteLine(""); response.WriteLine(""); exception = exception.InnerException; response.WriteLine(exception.Message); response.WriteLine(""); response.WriteLine(exception.StackTrace); } } }
public override void Process(Bamboo.WebServer.HttpRequest request, Bamboo.WebServer.HttpResponse response) { response.Headers.Add("Content-Type", this._contentType); System.IO.FileStream fileStream = System.IO.File.OpenRead(this._path); Copy(fileStream, response.Output); fileStream.Close(); }
public override void Process(Bamboo.WebServer.HttpRequest request, Bamboo.WebServer.HttpResponse response) { if (request.Method.ToUpper().Equals("GET")) { response.Headers.Add("Content-Type", this._contentType); response.Headers.Add("ETag", this._etag); response.Output.Write(this._content, 0, this._content.Length); } else { throw new System.Exception("Invalid method: " + request.Method); } }
public virtual void PreProcess(System.Net.Sockets.Socket socket, System.IO.Stream stream) { #region Process //socket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.SendTimeout, 15000); //socket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.ReceiveTimeout, 15000); Bamboo.WebServer.HttpRequest request = new Bamboo.WebServer.HttpRequest(); Bamboo.WebServer.HttpResponse response = new Bamboo.WebServer.HttpResponse(); byte[] buffer = new byte[8192]; try { ReadRequest(socket, stream, request, buffer); this._processor.Process(request, response); KeepCookies(request, response); WriteResponse(response, stream); stream.Flush(); } catch (System.Exception exception) { throw new System.Exception("HTTP ERROR", exception); } finally { if (buffer != null) { buffer = null; } if (request != null) { request.Dispose(); request = null; } if (response != null) { response.Dispose(); response = null; } } //stream.Flush(); //TODO DELETE stream.Close(); //TODO set everyting = null #endregion }
public override void Process(Bamboo.WebServer.HttpRequest request, Bamboo.WebServer.HttpResponse response) { //TODO check containskey instead. HttpProcessor processor = (HttpProcessor)this._processors[request.Path]; if (processor != null) { processor.Process(request, response); return; } else if (this._defaultProcessor != null) { this._defaultProcessor.Process(request, response); return; } else { response.Reset(); response.Status = 404; response.Headers.Add("Content-Type", "text/plain"); response.WriteLine("Page not found."); } }
public abstract void Process(Bamboo.WebServer.HttpRequest request, Bamboo.WebServer.HttpResponse response);
public override void PreProcess(System.Net.Sockets.Socket socket, System.IO.Stream stream) { // Address:Port info. string localAddress = ""; int localPort = 0; string remoteAddress = ""; int remotePort = 0; string start = System.DateTime.UtcNow.ToString(); byte[] request_bytes = null; byte[] response_bytes = null; System.Exception error = null; System.IO.MemoryStream requestStream = new System.IO.MemoryStream(); System.IO.MemoryStream responseStream = new System.IO.MemoryStream(); Bamboo.WebServer.TappedStream tappedStream = new Bamboo.WebServer.TappedStream(stream, requestStream, responseStream); Bamboo.WebServer.HttpRequest request = new Bamboo.WebServer.HttpRequest(); Bamboo.WebServer.HttpResponse response = new Bamboo.WebServer.HttpResponse(); byte[] buffer = new byte[8192]; try { // Address:Port info. string localEndPoint = socket.LocalEndPoint.ToString(); int index = localEndPoint.LastIndexOf(":"); localAddress = localEndPoint.Substring(0, index); localPort = Int32.Parse(localEndPoint.Substring(index + 1)); string remoteEndPoint = socket.RemoteEndPoint.ToString(); index = remoteEndPoint.LastIndexOf(":"); remoteAddress = remoteEndPoint.Substring(0, index); remotePort = Int32.Parse(remoteEndPoint.Substring(index + 1)); socket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.SendTimeout, 15000); socket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.ReceiveTimeout, 15000); ReadRequest(socket, tappedStream, request, buffer); this._processor.Process(request, response); KeepCookies(request, response); WriteResponse(response, tappedStream); tappedStream.Flush(); //TODO DELETE tappedStream.Close(); } catch (System.Exception exception) { error = exception; } finally { if (buffer != null) { buffer = null; } if (request != null) { request = null; } if (response != null) { response = null; } } requestStream.Flush(); responseStream.Flush(); request_bytes = requestStream.ToArray(); response_bytes = responseStream.ToArray(); requestStream.Close(); requestStream = null; responseStream.Close(); responseStream = null; string end = System.DateTime.UtcNow.ToString(); this.Log(localAddress, localPort, remoteAddress, remotePort, start, end, request_bytes, response_bytes, request, response, error); if (request != null) { request = null; } if (response != null) { response = null; } //TODO set everyting = null }