private GusServerRequest CreateRequest(GusHttpProcessor Processor) { Match m = pathParser.Match(Processor.SourceUrl); if (m == null || !m.Success) { return(null); } else { GusServerRequest req = new GusServerRequest(); req.Processor = Processor; req.Server = Processor.Server; req.RequestHeaders = Processor.RequestHeaders; req.Method = Processor.Method; req.SourceUrl = Processor.SourceUrl; req.Path = m.Groups[1].Value; req.RemoteIP = Processor.RemoteIP; req.RequestStream = Processor.InputStream; req.ResponseHeaders = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); req.Cookies = new Dictionary <string, string>(); req.PostVariables = new Dictionary <string, string>(); req.PostFiles = new Dictionary <string, GusPostFile>(); req.IsSsl = Processor.IsSecure; if (req.RequestHeaders.ContainsKey("Cookie")) { req.ParseCookie(req.RequestHeaders["Cookie"]); } //req.Path = req.Path.Substring(0, req.Path.Length - 1); req.QueryString = m.Groups[3].Value; req.ProtocolVersion = Processor.HttpProtocolVersion; req.ResponseStream = Processor.OutputStream; Dictionary <string, string> getVars = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var vars = ParseQueryString(req.QueryString);// HttpUtility.ParseQueryString(req.QueryString); foreach (string v in vars.Keys) { getVars.Add(v, vars[v]); } req.GetVariables = getVars; return(req); } }
public override void HandleRequest(GusHttpProcessor Processor) { GusServerRequest req = CreateRequest(Processor); GusServerPath path = null; lock (paths) { if (req == null || !paths.ContainsKey(req.Path)) { if (paths.ContainsKey("*")) { path = paths["*"]; } else { Processor.WriteNotFound(); return; } } else { path = paths[req.Path]; } } if (Processor.Method.ToLower() == "post") { Stream str = File.OpenRead(Processor.PostDataFile); if (req.RequestHeaders.ContainsKey("Content-Type") && req.RequestHeaders["Content-Type"].ToLower().StartsWith("multipart/")) { GusPostProcessor post = new GusPostProcessor(str, req.RequestHeaders["Content-Type"]); if (post.Success) { req.PostFiles = post.Files; req.PostVariables = post.Variables; } else { req.PostFiles = new Dictionary <string, GusPostFile>(StringComparer.OrdinalIgnoreCase); req.PostVariables = new Dictionary <string, string>(); StreamReader reader = new StreamReader(str); string data = reader.ReadToEnd(); var vars = ParseQueryString(data); foreach (string v in vars.Keys) { req.PostVariables.Add(v, vars[v]); } } } else { req.PostVariables = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); StreamReader reader = new StreamReader(str); string data = reader.ReadToEnd(); var vars = ParseQueryString(data); foreach (string v in vars.Keys) { req.PostVariables.Add(v, vars[v]); } } str.Close(); } try { path.ProcessRequest(req); } catch (Exception Ex) { try { req.ResponseStream.WriteText("<div style=\"background-color:#FFCC00; padding:10px\"><b>Execution error</b><br /><br />" + Ex.Message + "</div>"); } catch { } } if (req.Method.ToLower() == "post" && req.PostFiles != null) { foreach (var v in req.PostFiles) { if (v.Value.TempFile != null) { File.Delete(v.Value.TempFile); } } } }
public abstract void ProcessRequest(GusServerRequest Request);