예제 #1
0
파일: Rule.cs 프로젝트: fuqi0340/StaticHtml
        /// <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();
        }
예제 #2
0
 public Stream GenHTML(RequestInfo req)
 {
     using (var client = new TcpClient())
     {
         client.ReceiveTimeout = TIMEOUT;
         client.Connect(req.Host, req.Port);
         using (var stream = client.GetStream())
         {
             OutHeader(req, stream);
             return(HttpParseHelp.ToGzip(stream));
         }
     }
 }