Exemple #1
0
 public void RemovePath(GusServerPath Path)
 {
     lock (paths)
         paths.Remove(Path.Path);
 }
Exemple #2
0
        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);
                    }
                }
            }
        }
Exemple #3
0
 public void AddPath(GusServerPath Path)
 {
     lock (paths)
         paths.Add(Path.Path, Path);
 }