public override void BeforeHeaders(HttpResponse response) { if (IsPartial) response.StatusCode = HttpStatusCode.PartialContent; }
/// <summary> /// Hook for modifying the http response before headers are sent. /// </summary> /// <param name="response"></param> public virtual void BeforeHeaders(HttpResponse response) { }
void Close() { if (Closed) return; asyncArgs.Dispose(); response.Producer.Disconnect(); response.Producer.Dispose(); response = null; request = null; socket.Close(); Closed = true; }
/// <summary> /// Start writing the HTTP response. /// </summary> /// <param name="response"></param> public void AsyncWrite(HttpRequest request, HttpResponse response) { this.request = request; this.response = response; SendHeaders(); }
/// <summary> /// Async event handles HTTP requests received. /// </summary> /// <param name="request"></param> void ProcessRequest(HttpRequest request) { var handledByModule = false; lock (_modules) { foreach (var module in _modules) { if (module.ResponsibleForRequest(request)) { handledByModule = true; var args = new ProcessRequestEventArgs(); args.Request = request; args.Response = new HttpResponse() { HttpVersion = request.Version, StatusCode = HttpStatusCode.OK, Connection = HttpConnection.Close, Headers = new Dictionary<string,string>() }; args.Completed += ModuleProcessComplete; if (!module.ProcessAsync(args)) ModuleProcessComplete(module, args); } } } if (!handledByModule) { var response = new HttpResponse(); response.StatusCode = HttpStatusCode.NotFound; response.Headers.Add("Content-Type", "text/plain"); response.Producer = new BufferedProducer("404 - Not Found"); var writer = new HttpResponseWriter(request.ClientSocket); writer.AsyncWrite(request, response); } }
void ProcessHttpError(HttpStatusCode httpStatusCode, HttpRequest request) { var response = new HttpResponse(); response.StatusCode = httpStatusCode; response.Producer = new BufferedProducer("An error occurred, please hang tight"); var writer = new HttpResponseWriter(request.ClientSocket); writer.AsyncWrite(request, response); }