Fixed broken Content-Type header, was adding to text/html instead of replacing it

Added Server header to RestAPI responses
This commit is contained in:
stevenh 2012-02-16 11:14:52 +00:00
parent 2f7cb9f44e
commit 0108795f27

View file

@ -21,6 +21,7 @@ using System.ComponentModel;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Reflection;
using HttpServer;
using HttpServer.Headers;
using Newtonsoft.Json;
@ -41,6 +42,7 @@ namespace Rests
{
private readonly List<RestCommand> commands = new List<RestCommand>();
private HttpListener listener;
private StringHeader serverHeader;
public IPAddress Ip { get; set; }
public int Port { get; set; }
@ -48,6 +50,9 @@ namespace Rests
{
Ip = ip;
Port = port;
string appName = this.GetType().Assembly.GetName().Version.ToString();
AssemblyName ass = this.GetType().Assembly.GetName();
serverHeader = new StringHeader("Server", String.Format("{0}/{1}", ass.Name, ass.Version));
}
public virtual void Start()
@ -121,10 +126,10 @@ namespace Rests
var str = JsonConvert.SerializeObject(obj, Formatting.Indented);
e.Response.Connection.Type = ConnectionType.Close;
e.Response.Add(new ContentTypeHeader("application/json"));
e.Response.ContentType = new ContentTypeHeader("application/json");
e.Response.Add(serverHeader);
e.Response.Body.Write(Encoding.ASCII.GetBytes(str), 0, str.Length);
e.Response.Status = HttpStatusCode.OK;
return;
}
protected virtual object ProcessRequest(object sender, RequestEventArgs e)