public AddHeader ( string key, string value ) : void | ||
key | string | /// string containing the header field /// name /// |
value | string | /// string containing the header field /// value /// |
Résultat | void |
protected string GetContentType(string filename, OSHttpResponse response) { switch (Path.GetExtension(filename)) { case ".jpeg": case ".jpg": response.AddHeader("Cache-Control", "Public;max-age=" + CLIENT_CACHE_TIME.ToString()); return "image/jpeg"; case ".gif": response.AddHeader("Cache-Control", "Public;max-age=" + CLIENT_CACHE_TIME.ToString()); return "image/gif"; case ".png": response.AddHeader("Cache-Control", "Public;max-age=" + CLIENT_CACHE_TIME.ToString()); return "image/png"; case ".tiff": response.AddHeader("Cache-Control", "Public;max-age=" + CLIENT_CACHE_TIME.ToString()); return "image/tiff"; case ".html": case ".htm": case ".xsl": response.AddHeader("Cache-Control", "no-cache"); return "text/html"; case ".css": response.AddHeader("Cache-Control", "no-cache"); return "text/css"; case ".js": return "application/javascript"; } return "text/plain"; }
byte[] WriteTextureData(OSHttpRequest request, OSHttpResponse response, AssetBase texture, string format) { string range = request.Headers.GetOne("Range"); //MainConsole.Instance.DebugFormat("[GET TEXTURE]: Range {0}", range); if (!String.IsNullOrEmpty(range)) // JP2's only { // Range request int start, end; if (TryParseRange(range, out start, out end)) { // Before clamping start make sure we can satisfy it in order to avoid // sending back the last byte instead of an error status if (start >= texture.Data.Length) { response.StatusCode = (int) System.Net.HttpStatusCode.RequestedRangeNotSatisfiable; return MainServer.BlankResponse; } else { // Handle the case where portions of the range are missing. if (start == -1) start = 0; if (end == -1) end = int.MaxValue; end = Utils.Clamp(end, 0, texture.Data.Length - 1); start = Utils.Clamp(start, 0, end); int len = end - start + 1; //MainConsole.Instance.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID); if (len < texture.Data.Length) response.StatusCode = (int) System.Net.HttpStatusCode.PartialContent; else response.StatusCode = (int) System.Net.HttpStatusCode.OK; response.ContentType = texture.TypeString; response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length)); byte[] array = new byte[len]; Array.Copy(texture.Data, start, array, 0, len); return array; } } MainConsole.Instance.Warn("[GET TEXTURE]: Malformed Range header: " + range); response.StatusCode = (int) System.Net.HttpStatusCode.BadRequest; return MainServer.BlankResponse; } // Full content request response.StatusCode = (int) System.Net.HttpStatusCode.OK; response.ContentType = texture.TypeString; if (format == DefaultFormat) response.ContentType = texture.TypeString; else response.ContentType = "image/" + format; return texture.Data; }
internal void Redirect(OSHttpResponse httpResponse, string url) { httpResponse.StatusCode = (int) HttpStatusCode.Redirect; httpResponse.AddHeader("Location", url); httpResponse.KeepAlive = false; }
public byte[] GetHTML404(OSHttpResponse response) { // I know this statuscode is dumb, but the client doesn't respond to 404s and 500s response.StatusCode = 404; response.AddHeader ("Content-type", "text/html"); string responseString = GetHTTP404 (); byte [] buffer = Encoding.UTF8.GetBytes (responseString); response.SendChunked = false; response.ContentEncoding = Encoding.UTF8; return buffer; }