byte [] WriteTextureData (OSHttpRequest request, OSHttpResponse response, AssetBase texture, string format)
        {
            string range = request.Headers.GetOne ("Range");
            //MainConsole.Instance.DebugFormat("[GETTEXTURE]: 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 ("[AssetCAPS]: 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;

        }
 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", "max-age=" + CLIENT_CACHE_TIME.ToString() + ", public");
             response.AddHeader("Cache-Control", "no-cache");
             return "text/css";
         case ".js":
             //response.AddHeader("Cache-Control", "max-age=" + CLIENT_CACHE_TIME.ToString() + ", public");
             return "application/javascript";
     }
     return "text/plain";
 }
        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;
        }
 internal void Redirect(OSHttpResponse httpResponse, string url)
 {
     httpResponse.StatusCode = (int) HttpStatusCode.Redirect;
     httpResponse.AddHeader("Location", url);
     httpResponse.KeepAlive = false;
 }
        protected string GetContentType (string filename, OSHttpResponse response)
        {
            var setCache = true;    // default is to cache
            var mimeType = "";

            var ext = Path.GetExtension (filename);
            switch (ext) {
            case ".jpeg":
            case ".jpg":
                mimeType = "image/jpeg";
                break;
            case ".gif":
                mimeType = "image/gif";
                break;
            case ".png":
                mimeType = "image/png";
                break;
            case ".tiff":
                mimeType = "image/tiff";
                break;
            case ".woff":
                mimeType = "application/font-woff";
                break;
            case ".woff2":
                mimeType = "application/font-woff2";
                break;
            case ".ttf":
                mimeType = "application/font-ttf";
                break;
            case ".css":
                setCache = !filename.StartsWith ("styles", StringComparison.Ordinal);
                mimeType = "text/css";
                break;
            case ".html":
            case ".htm":
            case ".xsl":
                setCache = false;
                mimeType = "text/html";
                break;
            case ".js":
                setCache = !filename.Contains ("menu");     // must not cache menu generation
                mimeType = "application/javascript";
                break;
            default:
                mimeType = "text/plain";
                break;
            }

            if (setCache)
                response.AddHeader ("Cache-Control", "public, max-age=" + CLIENT_CACHE_TIME);
            else
                response.AddHeader ("Cache-Control", "no-cache");

            return mimeType;
        }