/// <summary> /// 缓存没过期,直接输出缓存 /// </summary> /// <param name="context"></param> /// <param name="key"></param> /// <param name="info"></param> private void ResponceCache(HttpContext context, string key, CacheInfo info) { var req = context.Request; var rep = context.Response; string time = info.StoreTime.ToString("r"); if (req.Headers["If-Modified-Since"] == time) { rep.StatusCode = (int)System.Net.HttpStatusCode.NotModified; LogHelp.Info("cache hit 304 " + req.RawUrl); } else { var httpInfo = new HttpInfo(); var _stream = Store.Get(key); int headEndPosition = 0; string firstLine = ""; httpInfo.Headers = HttpParseHelp.ParseHeader(_stream, ref headEndPosition, ref firstLine); rep.StatusCode = ParseRespondCode(firstLine); if (rep.StatusCode == 200) { rep.AppendHeader("Last-Modified", time); } httpInfo.Content = _stream; OutResponse(req, rep, httpInfo); LogHelp.Info("cache hit html " + req.RawUrl); } context.ApplicationInstance.CompleteRequest(); }
public void Init(HttpApplication context) { try { if (htmlSection.Run == "on") { core = HtmlStaticCore.GetInstance(htmlSection); context.BeginRequest += new EventHandler(context_BeginRequest); LogHelp.Info("int success! "); } else { LogHelp.Warn("run off! 请在staticHtml节点中添加属性run=\"on\" on:启用 off:关闭"); } } catch (Exception e) { LogHelp.Error("ini error! " + e.ToString()); } }