public void SendResponse(HttpStatusCode statusCode, string response = null) { var description = statusCode.ToString().ConvertCamelCase(); var body = (!string.IsNullOrWhiteSpace(response)) ? response : $"<h1>{description}</h1>"; var buffer = Encoding.UTF8.GetBytes(body); StatusDescription = description; StatusCode = (int)statusCode; ContentType = Util.ContentType.HTML.ToValue(); FlushResponse(buffer); }
public void SendResponse(HttpStatusCode statusCode, string response = null) { StatusDescription = statusCode.ToString().ConvertCamelCase(); StatusCode = statusCode; byte[] buffer; if (string.IsNullOrWhiteSpace(response)) { ContentType = ContentType.HTML; buffer = Encoding.ASCII.GetBytes($"<h1>{StatusDescription}</h1>"); } else { buffer = ContentEncoding.GetBytes(response); } FlushResponse(buffer); }
public void SendResponse(HttpStatusCode statusCode, Exception exception) { SendResponse(statusCode, $"{exception.Message}{Environment.NewLine}<br>{Environment.NewLine}{exception.StackTrace}"); }