Beispiel #1
0
        Request(Stream stream, StreamWriter sw, string path, string method, HeaderDictionary headers, byte[] body)
        {
            Stream       = stream;
            StreamWriter = sw;
            if (path.Contains("?"))
            {
                string query;
                (RealPath, query) = path.Split('?', 2);
                Query             = ParseQueryOrPost(query);
            }
            else
            {
                RealPath = path;
                Query    = new Dictionary <string, string>();
            }

            Method  = method;
            Headers = headers;
            Body    = body;

            if (headers.ContainsKey("Content-Type") && headers["Content-Type"] == "application/x-www-form-urlencoded")
            {
                PostParameters = ParseQueryOrPost(Encoding.UTF8.GetString(Body));
            }

            if (headers.ContainsKey("Cookie"))
            {
                Cookies = headers.GetList("Cookie").Select(
                    x => x.Split(';').Select(y => y.Trim().Split('=', 2)).Where(y => y.Length == 2))
                          .SelectMany(x => x)
                          .ToDictionary(x => x[0], x => x[1]);
            }
            else
            {
                Cookies = new Dictionary <string, string>();
            }
        }