private FeintSDK.Url UrlDispatcher(FeintSDK.Request req, FeintSDK.RequestMethod actualMethod) { FeintSDK.Url urlApp = null; for (int i = 0; i < FeintSDK.Settings.Urls.Count; i++) { var match = Regex.Match(req.Url.ToString(), FeintSDK.Settings.Urls[i].UrlMatch); if (match.Success && (FeintSDK.Settings.Urls[i].Method == FeintSDK.RequestMethod.ALL || actualMethod == FeintSDK.Settings.Urls[i].Method)) { urlApp = FeintSDK.Settings.Urls[i]; setNonPublicSetProperty(req, req.GetType(), "Variables", match.Groups); break; } } return urlApp; }
private void ParseContent(Request request, FeintSDK.Request req, string text) { if (text.Length > 0) { if (request.ContentType.Value.MediaType == "application/json") { req.FormData = JsonConvert.DeserializeObject<Dictionary<string, string>>(text); } else if (!request.ContentType.Value.MediaType.StartsWith("multipart/form-data")) { req.FormData = new Dictionary<string, string>(parseContent(text)); } else { req.FormData = new Dictionary<string, string>(); string[] postTab = text.Replace("\r", "").Split('\n'); String postName = ""; for (int i = 0; i < postTab.Length; i++) { if (postTab[i].StartsWith("------")) continue; if (postTab[i].StartsWith("Content-Disposition: form-data;")) { postName = HttpUtility.UrlDecode(postTab[i].Substring(38, postTab[i].LastIndexOf("\"") - 38)).Trim(); continue; } if (postTab[i].Length > 0) { req.FormData.Add(postName, HttpUtility.UrlDecode(postTab[i]).Trim()); } } } } }
private static void setSesion(Request request, Response response, FeintSDK.Request req) { if (request.Cookies.ContainsKey("session")) { var c = request.Cookies["session"]; string key = req.Session.Start(c.Value); if (c.Value.CompareTo(key) != 0) { try { response.SetCookie(new Cookie("session", key, "/")); } catch (NullReferenceException) { response.SetCookie(new Cookie("session", key, "/")); } } } else { response.SetCookie(new Cookie("session", req.Session.Start(), "/")); } }
private FeintSDK.Response GetStatic(Response response, FeintSDK.Response res, FeintSDK.Request req) { if (req.Url.Contains("./") || req.Url.ToString().Contains("..")) res = null; else { try { byte[] buffer; string path = req.Url.Substring(1); if (FeintSDK.Settings.StaticCache) { if (staticCache.ContainsKey(path)) { buffer = staticCache[path]; } else { FileStream fs = new FileStream("FeintSite/" + path, FileMode.Open, FileAccess.Read); buffer = new byte[fs.Length]; fs.Read(buffer, 0, (int)fs.Length); fs.Close(); staticCache.Add(path, buffer); } } else { FileStream fs = new FileStream("FeintSite/" + path, FileMode.Open, FileAccess.Read); buffer = new byte[fs.Length]; fs.Read(buffer, 0, (int)fs.Length); fs.Close(); } res = new FeintSDK.Response(buffer); string ext = req.Url.Substring(req.Url.LastIndexOf("."), req.Url.Length - req.Url.LastIndexOf(".")); response.SetHeader(ResponseHeader.HttpContentType, GetMimeType(ext) + "; charset=utf-8"); } catch { } } return res; }
private static FeintSDK.Response RunApplication(Response response, FeintSDK.Response res, FeintSDK.Request req, FeintSDK.Url urlApp) { MethodInfo mi = urlApp.View.GetMethodInfo(); FeintSDK.AOPAttribute[] aops = (FeintSDK.AOPAttribute[])mi.GetCustomAttributes(typeof(FeintSDK.AOPAttribute), true); res = null; foreach (var aop in aops) { res = aop.PreRequest(req); } if (res == null) { res = urlApp.View(req); if (res.MimeType != null) { response.SetHeader(ResponseHeader.HttpContentType, res.MimeType + "; charset=utf-8"); } } foreach (var aop in aops) { aop.PostRequest(req); } return res; }