Exemplo n.º 1
0
            public void ProcessRequest(HttpContext context)
            {
                var version = ClientScriptReference.GetContentHash(context.Request.Url.AbsolutePath);

                if (string.Equals(context.Request.Headers["If-None-Match"], version))
                {
                    context.Response.StatusCode = (int)HttpStatusCode.NotModified;
                }
                else
                {
                    context.Response.Write(CopyrigthTransform.CopyrigthText);
                    context.Response.Write(ClientScriptReference.GetContent(context.Request.Url.AbsolutePath));
                    context.Response.Charset     = Encoding.UTF8.WebName;
                    context.Response.ContentType = new ContentType("application/x-javascript")
                    {
                        CharSet = Encoding.UTF8.WebName
                    }.ToString();

                    // cache
                    context.Response.Cache.SetVaryByCustom("*");
                    context.Response.Cache.SetAllowResponseInBrowserHistory(true);
                    context.Response.Cache.SetETag(version);
                    context.Response.Cache.SetCacheability(HttpCacheability.Public);
                    context.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
                }
            }
Exemplo n.º 2
0
            public override async Task ProcessRequestAsync(HttpContext context)
            {
                try
                {
                    HttpContext.Current = context;
                    var clientScriptReference = new ClientScriptReference();
                    var version = clientScriptReference.GetContentHash(context.Request.Url.AbsolutePath);
                    if (string.Equals(context.Request.Headers["If-None-Match"], version))
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.NotModified;
                    }
                    else
                    {
                        context.Response.Charset     = Encoding.UTF8.WebName;
                        context.Response.ContentType = new ContentType("application/x-javascript")
                        {
                            CharSet = Encoding.UTF8.WebName
                        }.ToString();

                        // cache
                        context.Response.Cache.SetVaryByCustom("*");
                        context.Response.Cache.SetAllowResponseInBrowserHistory(true);
                        context.Response.Cache.SetETag(version);
                        context.Response.Cache.SetCacheability(HttpCacheability.Public);

                        // body
                        var content = Encoding.UTF8.GetBytes(await clientScriptReference.GetContentAsync(context));

                        using (var inputStream = new MemoryStream())
                        {
                            if (ClientSettings.GZipEnabled)
                            {
                                using (var zip = new GZipStream(inputStream, CompressionMode.Compress, true))
                                {
                                    await zip.WriteAsync(content, 0, content.Length);

                                    zip.Flush();
                                }
                                context.Response.Headers["Content-Encoding"] = "gzip";
                            }
                            else
                            {
                                await inputStream.WriteAsync(content, 0, content.Length);
                            }
                            inputStream.Position = 0;
                            inputStream.CopyTo(context.Response.OutputStream);
                        }
                    }
                }
                catch (Exception e)
                {
                    LogManager.GetLogger("ASC").Error("ClientScriptHandler", e);
                }
            }