Esempio n. 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);
            }
        }
Esempio n. 2
0
        private void OnHttpDisconnect(object sender, BeetleX.EventArgs.SessionEventArgs e)
        {
            BeetleX.ISession session = e.Session;
            HttpToken        token   = (HttpToken)e.Session.Tag;

            if (session.Name != null && token != null)
            {
                Room room = GetRoom(e.Session);
                room?.CheckOut(token.WebSocketRequest, mServer);
            }
            lock (mAdminList)
                mAdminList.Remove(session);
        }
Esempio n. 3
0
        public void Send(ISession session)
        {
            HttpToken token = (HttpToken)session.Tag;

            if (token != null && token.WebSocket)
            {
                session.Send(this);
                if (session.Server.EnableLog(EventArgs.LogType.Info))
                {
                    session.Server.Log(EventArgs.LogType.Info, session, "{0} websocket send data {1}", session.RemoteEndPoint, this.Type.ToString());
                }
            }
        }
        public void SendDataFrame(DataFrame data, ISession session)
        {
            if (session == null)
            {
                return;
            }
            HttpToken toke = (HttpToken)session.Tag;

            if (toke.WebSocket)
            {
                session.Send(data);
            }
        }
Esempio n. 5
0
        private void OutputFileResource(FileContentType fct, FileResource fr, HttpResponse response)
        {
            if (!Debug)
            {
                if (response.Request.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);
                    }
                    response.NoModify();
                    return;
                }
            }
            else
            {
                fr.Load();
            }

            if (fr.GZIP)
            {
                SetGZIP(response);
            }
            if (!Debug)
            {
                if (fr.Cached)
                {
                    response.Header.Add(HeaderType.CACHE_CONTROL, "private, max-age=31536000");
                }
                else
                {
                    response.Header.Add(HeaderType.ETAG, fr.FileMD5);
                }
            }
            SetChunked(response);
            HttpToken token = (HttpToken)response.Session.Tag;

            token.File = fr.CreateFileBlock();
            response.SetContentType(fct.ContentType);
            response.Result(token.File);
            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);
            }
        }
        /// <summary>
        /// Get HTTP token signature.
        /// </summary>
        /// <returns>Returns token.</returns>
        public HttpToken GetSignature()
        {
            try
            {
                if (_merchantConfig == null)
                {
                    return(null);
                }

                HttpToken token = (HttpToken) new HttpTokenGenerator(_merchantConfig).GetToken();
                return(token);
            }
            catch (Exception ex)
            {
                throw new TokenException(ex.Message, ex);
            }
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        public void Send(ISession session, bool isError = false)
        {
            HttpToken token = (HttpToken)session.Tag;

            if (token != null && token.WebSocket)
            {
                if (isError)
                {
                    mServer.IncrementResponsed(token.Request, null, 0, HttpApiServer.WEBSOCKET_ERROR, null);
                }
                else
                {
                    mServer.IncrementResponsed(token.Request, null, 0, HttpApiServer.WEBSOCKET_SUCCESS, null);
                }
                session.Send(this);
                if (session.Server.EnableLog(EventArgs.LogType.Info))
                {
                    session.Server.Log(EventArgs.LogType.Info, session, $"Websocket {token?.Request?.ID} {token?.Request?.RemoteIPAddress} websocket send data {this.Type.ToString()}");
                }
            }
        }
        public HttpToken GetSignature()
        {
            try
            {
                if (this._merchantConfig == null)
                {
                    return((HttpToken)null);
                }

                Enumerations.ValidateRequestType(this._merchantConfig.RequestType);
                if (string.IsNullOrEmpty(this._merchantConfig.MerchantId) || string.IsNullOrEmpty(this._merchantConfig.MerchantKeyId) || string.IsNullOrEmpty(this._merchantConfig.MerchantSecretKey))
                {
                    throw new Exception("Missing or Empty Credentials : MerchantID or MerchantKeyID or MerchantSecretKey");
                }
                HttpToken token = (HttpToken) new HttpTokenGenerator(this._merchantConfig).GetToken();

                return(token);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 10
0
        private void OutputFileResource(FileContentType fct, FileResource fr, HttpResponse response)
        {
            if (!Debug)
            {
                if (response.Request.IfNoneMatch == fr.FileMD5)
                {
                    response.NoModify();
                    return;
                }
            }
            else
            {
                fr.Load();
            }

            if (fr.GZIP)
            {
                SetGZIP(response);
            }
            if (!Debug)
            {
                if (fr.Cached)
                {
                    response.Header.Add(HeaderType.CACHE_CONTROL, "private, max-age=31536000");
                }
                else
                {
                    response.Header.Add(HeaderType.ETAG, fr.FileMD5);
                }
            }
            SetChunked(response);
            HttpToken token = (HttpToken)response.Session.Tag;

            token.File = new FileBlock(fr);
            response.SetContentType(fct.ContentType);
            response.Result(token.File);
        }
Esempio n. 11
0
        public void OutputFile(FileResult result, HttpRequest request, HttpResponse response)
        {
            var file = result.File;

            if (file.IndexOf(System.IO.Path.DirectorySeparatorChar) == -1)
            {
                var vfile = MatchVirtuslFolder(file);
                if (vfile == null)
                {
                    file = file.Replace('/', System.IO.Path.DirectorySeparatorChar);
                    if (file[0] != System.IO.Path.DirectorySeparatorChar)
                    {
                        file = System.IO.Path.DirectorySeparatorChar + file;
                    }
                    var basePath = Server.Options.StaticResourcePath;
                    if (basePath[basePath.Length - 1] == System.IO.Path.DirectorySeparatorChar)
                    {
                        file = basePath + file.Substring(1);
                    }
                    else
                    {
                        file = basePath + file;
                    }
                }
                else
                {
                    file = vfile;
                }
            }
            var    resource        = new StaticResurce.NoCacheResource(file, "");
            string ext             = System.IO.Path.GetExtension(file).Replace(".", "");
            var    fileContentType = new StaticResurce.FileContentType(ext);

            if (!string.IsNullOrEmpty(result.ContentType))
            {
                fileContentType.ContentType = result.ContentType;
            }
            resource.GZIP = result.GZip;
            EventFileResponseArgs efra = new EventFileResponseArgs();

            efra.Request     = response.Request;
            efra.Response    = response;
            efra.Resource    = resource;
            efra.ContentType = fileContentType;
            FileResponse?.Invoke(this, efra);
            if (!efra.Cancel)
            {
                if (!System.IO.File.Exists(file))
                {
                    NotFoundResult notFound = new NotFoundResult("{0} file not found", request.Url);
                    response.Result(notFound);
                }
                else
                {
                    efra.Resource.Load();
                    if (efra.Resource.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 {efra.Resource.GZIP}");
                    }
                    HttpToken token = (HttpToken)response.Session.Tag;
                    token.File = efra.Resource.CreateFileBlock();
                    response.SetContentType(efra.ContentType.ContentType);
                    response.Result(token.File);
                }
            }
        }