Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion SimpleHttpServer/HttpProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ private static void WriteResponse(Stream stream, HttpResponse response) {

// default to text/html content type
if (!response.Headers.ContainsKey("Content-Type")) {
response.Headers["Content-Type"] = "text/html";
string type = "text/html";
if (!string.IsNullOrWhiteSpace(response.CharsetName))
{
type += "; charset=" + response.CharsetName;
}
response.Headers["Content-Type"] = type;
}

response.Headers["Content-Length"] = response.Content.Length.ToString();
Expand Down
2 changes: 2 additions & 0 deletions SimpleHttpServer/Models/HttpResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class HttpResponse
public string StatusCode { get; set; }
public string ReasonPhrase { get; set; }
public byte[] Content { get; set; }
public string CharsetName { get; protected set; }

public Dictionary<string, string> Headers { get; set; }

Expand All @@ -55,6 +56,7 @@ public void setContent(string content, Encoding encoding = null)
{
encoding = Encoding.UTF8;
}
CharsetName = encoding.WebName;
Content = encoding.GetBytes(content);
}

Expand Down