Beispiel #1
0
        private void OutputFileResource(FileContentType fct, FileResource fr, HttpResponse response)
        {
            if (!Debug)
            {
                string IfNoneMatch = response.Request.IfNoneMatch;
                if (!string.IsNullOrEmpty(IfNoneMatch) && IfNoneMatch == fr.FileMD5)
                {
                    if (Server.EnableLog(EventArgs.LogType.Info))
                    {
                        Server.BaseServer.Log(EventArgs.LogType.Info, null, $"HTTP {response.Request.ID} {response.Request.RemoteIPAddress} get {response.Request.Url} source no modify ");
                    }
                    if (Server.Options.StaticResurceCacheTime > 0)
                    {
                        response.Header.Add(HeaderTypeFactory.CACHE_CONTROL, "public, max-age=" + Server.Options.StaticResurceCacheTime);
                    }
                    NoModifyResult result = new NoModifyResult();
                    response.Result(result);
                    return;
                }
            }
            if (!Debug)
            {
                if (!string.IsNullOrEmpty(fr.FileMD5))
                {
                    response.Header.Add(HeaderTypeFactory.ETAG, fr.FileMD5);
                    if (Server.Options.StaticResurceCacheTime > 0)
                    {
                        response.Header.Add(HeaderTypeFactory.CACHE_CONTROL, "public, max-age=" + Server.Options.StaticResurceCacheTime);
                    }
                }
            }
            EventFileResponseArgs efra = new EventFileResponseArgs();

            efra.Request  = response.Request;
            efra.Response = response;
            efra.Resource = fr;
            FileResponse?.Invoke(this, efra);
            if (!efra.Cancel)
            {
                if (fr.GZIP)
                {
                    SetGZIP(response);
                }
                SetChunked(response);
                if (Server.EnableLog(EventArgs.LogType.Info))
                {
                    Server.BaseServer.Log(EventArgs.LogType.Info, null, $"HTTP {response.Request.ID} {response.Request.RemoteIPAddress} get {response.Request.BaseUrl} response gzip {fr.GZIP}");
                }
                HttpToken token = (HttpToken)response.Session.Tag;
                token.File = fr.CreateFileBlock();
                response.SetContentType(fct.ContentType);
                response.Result(token.File);
            }
        }
Beispiel #2
0
        private void OutputFileResource(FileContentType fct, FileResource fr, HttpResponse response)
        {
            if (!Debug)
            {
                string IfNoneMatch = response.Request.IfNoneMatch;
                if (!string.IsNullOrEmpty(IfNoneMatch) && IfNoneMatch == fr.FileMD5)
                {
                    if (Server.EnableLog(EventArgs.LogType.Info))
                    {
                        Server.BaseServer.Log(EventArgs.LogType.Info, null, "{0} get {1} source no modify ", response.Request.ClientIPAddress, response.Request.Url);
                    }
                    NoModifyResult result = new NoModifyResult();
                    response.Result(result);
                    return;
                }
            }
            if (fr.GZIP)
            {
                SetGZIP(response);
            }
            if (!Debug)
            {
                if (!string.IsNullOrEmpty(fr.FileMD5))
                {
                    response.Header.Add(HeaderTypeFactory.ETAG, fr.FileMD5);
                }
            }
            SetChunked(response);
            EventFileResponseArgs efra = new EventFileResponseArgs();

            efra.Request  = response.Request;
            efra.Response = response;
            efra.Resource = fr;
            FileResponse?.Invoke(this, efra);
            if (Server.EnableLog(EventArgs.LogType.Info))
            {
                Server.BaseServer.Log(EventArgs.LogType.Info, response.Request.Session, "{0} get {1} response gzip {2}",
                                      response.Request.ClientIPAddress, response.Request.BaseUrl, fr.GZIP);
            }
            HttpToken token = (HttpToken)response.Session.Tag;

            token.File = fr.CreateFileBlock();
            response.SetContentType(fct.ContentType);
            response.Result(token.File);
        }