Apachai.StaticContentModule.Content C# (CSharp) Method

Content() public method

public Content ( IManosContext ctx, string path ) : void
ctx IManosContext
path string
return void
        public void Content(IManosContext ctx, string path)
        {
            if (path.StartsWith ("/"))
                path = path.Substring (1);

            string etag, fileEtag;
            if (cacheExtensions != null
                && ctx.Request.Headers.TryGetNormalizedValue ("If-None-Match", out etag)
                && etagCache.TryGetValue (path, out fileEtag)
                && fileEtag.Equals (etag, StringComparison.Ordinal)) {

                ctx.Response.StatusCode = 304;
                ctx.Response.End ();
                return;
            }

            if (ValidFile (path)) {
                var mime = ManosMimeTypes.GetMimeType (path);
                if (mime.StartsWith ("text/", StringComparison.Ordinal) || mime.EndsWith ("javascript", StringComparison.Ordinal))
                    mime += "; charset=utf-8";

                ctx.Response.Headers.SetNormalizedHeader ("Content-Type", mime);

                // Expires setting for specific files
                string extension = Path.GetExtension (path);
                if (cacheExtensions != null && !string.IsNullOrEmpty (extension) && cacheExtensions.Contains (extension)) {
                    ctx.Response.Headers.SetNormalizedHeader ("Expires", expires);
                    ctx.Response.Headers.SetNormalizedHeader ("Cache-Control", cacheControl);
                    if (!etagCache.ContainsKey (path))
                        etagCache[path] = GetEtagFromFile (path);
                    ctx.Response.Headers.SetNormalizedHeader ("ETag", etagCache[path]);
                }

                ctx.Response.SendFile (path);
            } else
                ctx.Response.StatusCode = 404;

            ctx.Response.End ();
        }

Same methods

StaticContentModule::Content ( IManosContext ctx ) : void