예제 #1
0
 public static void EnableHttpCompression(HttpContext Context)
 {
     if (!string.IsNullOrEmpty(Context.Request.Headers.Get("Accept-Encoding")))
     {
         string   acceptEncoding = Context.Request.Headers["Accept-Encoding"];
         string[] types          =
             acceptEncoding.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
         if (types.Length > 0)
         {
             CompressingFilter filter =
                 HttpCompression.GetFilterForScheme(types, Context.Response.Filter);
             if (null != filter)
             {
                 Context.Response.Filter = filter;
             }
         }
     }
 }
예제 #2
0
        public void ProcessRequest(HttpContext context)
        {
            XmlDocument doc = (XmlDocument)context.Cache["doc"];

            if (doc == null)
            {
                XmlTextReader xml =
                    new XmlTextReader(
                        context.Server.MapPath(
                            ConfigurationSettings.AppSettings["MetaFeedRssInputPath"]));

                xml.Read();
                doc = new XmlDocument();
                doc.Load(xml);
                doc.RemoveChild(doc.FirstChild);
                context.Cache.Insert("doc", doc, new CacheDependency(context.Server.MapPath(ConfigurationSettings.AppSettings["MetaFeedRssInputPath"])));
                context.Cache["etag"] = Guid.NewGuid();
                xml.Close();
            }

            string ownETag    = context.Cache["etag"].ToString();
            string clientETag = context.Request.Headers.Get("If-None-Match");

            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.Cache.SetETag(ownETag);

            if (ownETag == clientETag)
            {
                context.Response.StatusCode = 304;
                context.Response.Flush();
                context.Response.End();
            }
            else
            {
                HttpCompression.EnableHttpCompression(context);
                context.Response.Write(doc.InnerXml);
                context.Response.ContentType = "application/rss+xml";
                context.Response.End();
            }
        }