public void SendContent(HttpListenerResponse res, string path, byte[] content) { string mimeType = HFTMimeType.GetMimeType(path); res.ContentType = mimeType; if (mimeType.StartsWith("text/") || mimeType == "application/javascript") { res.ContentEncoding = System.Text.Encoding.UTF8; } res.StatusCode = (int)HttpStatusCode.OK; res.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1. res.AddHeader("Pragma", "no-cache"); // HTTP 1.0. res.AddHeader("Expires", "0"); // Proxies. res.WriteContent(content); }
public void SendJsonBytes(HttpListenerResponse res, byte[] data) { res.StatusCode = (int)HttpStatusCode.OK; res.ContentType = "application/json"; res.ContentEncoding = System.Text.Encoding.UTF8; res.AddHeader("Access-Control-Allow-Origin", "*"); res.WriteContent(data); }
bool HandleRoot(string path, HttpListenerRequest req, HttpListenerResponse res) { if (path.Equals("/index.html") || path.Equals("/enter-name.html")) { var uri = req.Url; string url = uri.GetLeftPart(UriPartial.Authority) + m_gamePath + m_options.controllerFilename + uri.Query + uri.Fragment; res.StatusCode = (int)HttpStatusCode.Redirect; res.AddHeader("Location", url); res.ContentType = "text/html"; res.WriteContent(System.Text.Encoding.UTF8.GetBytes("<script>window.location.href = decodeURIComponent(\"" + Uri.EscapeDataString(url) + "\");</script>")); m_log.Info("redirect: " + url); return true; } return false; }