protected void WriteResponse(HttpListenerResponse response, string content, int status, IDictionary<string, string> headers)
{
if (headers != null)
{
foreach (var kvp in headers)
{
string name = kvp.Key;
string value = kvp.Value;
if (string.Equals(name, "Content-Length", StringComparison.OrdinalIgnoreCase))
response.ContentLength64 = long.Parse(value, CultureInfo.InvariantCulture);
else
response.Headers[kvp.Key] = kvp.Value;
}
}
response.StatusCode = status;
byte[] responseBytes = Encoding.UTF8.GetBytes(content);
using (response.OutputStream)
using (MemoryStream stream = new MemoryStream(responseBytes))
{
response.OutputStream.Write(responseBytes, 0, responseBytes.Length);
}
}
protected virtual void Cleanup()