Beispiel #1
0
        public virtual void SetLocation(string url)
        {
            Url = url ?? throw new ArgumentNullException(url);
            GetParameter.Clear();
            var match = UrlRegex.Match(url);

            if (!match.Success)
            {
                DocumentPath      = url;
                DocumentPathTiles = new[] { url };
                CompleteGet       = "";
            }
            DocumentPath      = match.Groups[1].Value;
            DocumentPathTiles = match.Groups[2].Captures
                                .OfType <Capture>()
                                .Select(c => WebServerUtils.DecodeUri(c.Value))
                                .ToArray();
            CompleteGet = match.Groups[3].Success ? match.Groups[3].Value ?? "" : "";
            foreach (Capture capture in match.Groups[4].Captures)
            {
                var submatch = ArgsRegex.Match(capture.Value);
                if (submatch.Success)
                {
                    GetParameter[WebServerUtils.DecodeUri(submatch.Groups[1].Value)]
                        = WebServerUtils.DecodeUri(submatch.Groups[2].Value);
                }
                else
                {
                    GetParameter[capture.Value] = "";
                }
            }
        }
            public override string ToString()
            {
                var sb = new StringBuilder();

                sb.Append(WebServerUtils.EncodeUri(Name.ToString()));
                sb.Append('=');
                sb.Append(WebServerUtils.EncodeUri(Value.ToString()));
                if (Expires != new DateTime(9999, 12, 31))
                {
                    sb.Append(";expires=");
                    sb.Append(WebServerUtils.GetDateString(Expires));
                }
                if (MaxAge != -1)
                {
                    sb.Append(";Max-Age=");
                    sb.Append(MaxAge);
                }
                sb.Append(";Path=");
                sb.Append(Path);
                return(sb.ToString());
            }
        public virtual void SetRequestCookieString(string cookie)
        {
            CompleteRequestCookie = cookie ?? throw new ArgumentNullException(nameof(cookie));
            AddedCookies.Clear();
            var reqCookie = new Dictionary <string, Cookie>();

            if (CompleteRequestCookie != "")
            {
                var tiles = CompleteRequestCookie.Split('&', ';');
                foreach (var tile in tiles)
                {
                    var ind = tile.IndexOf('=');
                    if (ind == -1)
                    {
                        var key = WebServerUtils.DecodeUri(tile.Trim());
                        if (!reqCookie.ContainsKey(key))
                        {
                            reqCookie.Add(key, new Cookie(key, ""));
                        }
                    }
                    else
                    {
                        var key   = WebServerUtils.DecodeUri(tile.Remove(ind).Trim());
                        var value = ind + 1 == tile.Length ? "" : WebServerUtils.DecodeUri(tile[(ind + 1)..]);