/// <summary> /// /// </summary> /// <param name="packageReader"></param> /// <param name="package"></param> /// <returns></returns> protected virtual bool TryBuildPackage(PackageReader packageReader, out RequestPackage package) { package = null; Guid proxySid; packageReader.TryGetParam("ssid", out proxySid); int actionid; if (!packageReader.TryGetParam("actionid", out actionid)) { return false; } int msgid; if (!packageReader.TryGetParam("msgid", out msgid)) { return false; } int userId; packageReader.TryGetParam("uid", out userId); string sessionId; string proxyId; packageReader.TryGetParam("sid", out sessionId); packageReader.TryGetParam("proxyId", out proxyId); package = new RequestPackage(msgid, sessionId, actionid, userId) { ProxySid = proxySid, ProxyId = proxyId, IsProxyRequest = packageReader.ContainsKey("isproxy"), RouteName = packageReader.RouteName, IsUrlParam = true, Params = packageReader.Params, Message = packageReader.InputStream, OriginalParam = packageReader.RawParam }; return true; }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <param name="package"></param> /// <param name="statusCode"></param> /// <returns></returns> public bool TryDecodePackage(HttpListenerRequest request, out RequestPackage package, out int statusCode) { statusCode = (int)HttpStatusCode.OK; string data = ""; if (Environment.OSVersion.Platform == PlatformID.Unix) { //The RawUrl Get is exist "/xxx.aspx?d=" char on the platform of mono. int index; if (String.Compare(request.HttpMethod, "get", StringComparison.OrdinalIgnoreCase) == 0 && (index = request.RawUrl.IndexOf("?d=", StringComparison.OrdinalIgnoreCase)) != -1) { data = request.RawUrl.Substring(index + 3); data = HttpUtility.UrlDecode(data); } else { data = request.RawUrl; } } else { data = request.QueryString["d"]; } var packageReader = new PackageReader(data, request.InputStream, request.ContentEncoding); return TryBuildPackage(packageReader, out package); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="package"></param> /// <returns></returns> public virtual bool TryDecodePackage(HttpContext context, out RequestPackage package) { package = null; if (context == null) { return false; } var data = context.Request["d"] ?? ""; var packageReader = new PackageReader(data, context.Request.InputStream, context.Request.ContentEncoding); return TryBuildPackage(packageReader, out package); }
/// <summary> /// Decode request package /// </summary> /// <param name="e"></param> /// <param name="package"></param> /// <returns></returns> public virtual bool TryDecodePackage(ConnectionEventArgs e, out RequestPackage package) { var packageReader = new PackageReader(e.Data, Encoding.UTF8); if (TryBuildPackage(packageReader, out package)) { package.OpCode = e.Meaage.OpCode; package.CommandMessage = e.Socket.IsWebSocket && e.Meaage.OpCode == OpCode.Text ? e.Meaage.Message : null; return true; } return false; }