private void ProcessRequest(object sender, HttpRequestEventArgs e)
        {
            try
            {
                var request = new RackRequest();
                var response = new RackResponse(e.RequestContext.Response.OutputStream);

                PrepareRackRequest(e.RequestContext.Request, request);
                _rack.HandleRequest(request, response);

                response.Status = response.Status;
                foreach (var header in response.Headers)
                    if (header.Key.ToLower() != "content-length") //Cannot set directly
                        e.RequestContext.Response.Headers.Add(header.Key, header.Value);

                
            }
            catch (HttpListenerException)
            {
                return;
            }
            catch (Exception ex)
            {
                RequestProcessingError(this, new HttpRequestErrorEventArgs(e.RequestContext,ex));
                var writer = new StreamWriter(e.RequestContext.Response.OutputStream);
                writer.Write(ex.ToString());
                writer.Flush();
                
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            var request = new RackRequest();
            var response = new RackResponse(context.Response.OutputStream);

            PrepareRackRequest(request, context.Request);

            _rack.HandleRequest(request, response);

            context.Response.StatusCode = response.Status;
            foreach (var header in response.Headers)
                context.Response.AppendHeader(header.Key, header.Value);
        }
        public override bool Process(IHttpRequest request, IHttpResponse response, IHttpSession session)
        {
            _log.Write(this, LogPrio.Trace, String.Format("Begin handling Rack request for {0}", request.Uri));

            var rackRequest = request.ToRackRequest();
            var rackResponse = new RackResponse(response.Body);

            //this will write to the body. We may want to set headers first, so may need some thought.
            _rack.HandleRequest(rackRequest, rackResponse);

            response.Status = (HttpStatusCode)rackResponse.Status;
            foreach (var header in rackResponse.Headers)
                if (header.Key.ToLower() != "content-length")
                    response.AddHeader(header.Key, header.Value);

            _log.Write(this, LogPrio.Trace, String.Format("Finished handling Rack request for {0}", request.Uri));

            return true;
        }