public void SetCookies(CookieCollection cookies)
        {
            if (cookies.IsNull() || cookies.Count == 0)
            {
                return;
            }

            foreach (var cookie in cookies.Sorted)
            {
                AddHeader("Set-Cookie", cookie.ToResponseString());
            }
        }
Exemplo n.º 2
0
            public void SendResponseData(Stream writerStream)
            {
                if (!_cookies.IsNull())
                {
                    _responseHeader.Add(_cookies.ToResponseData(), null);
                }

                _responseHeader.Add("Connection", "Keep-Alive");
                _responseHeader.Add("\r\n", null);

                var retBytes = Encoding.UTF8.GetBytes(_responseHeader.Aggregate("", (current, header) => current + header.Key + (header.Value != null ? $":{header.Value}" : "") + Environment.NewLine)).ToArray();

                writerStream.Write(retBytes, 0, retBytes.Length);

                while (ContentStream.Position < ContentStream.Length)
                {
                    ContentStream.CopyTo(writerStream, BufferSize);
                    Task.Delay(500);
                }
            }
        public void SetCookies(CookieCollection cookies)
        {
            if (cookies.IsNull() || cookies.Count == 0)
            {
                return;
            }

            var sorted = cookies.Sorted.ToArray();
            var header = new StringBuilder(sorted[0].ToString());

            for (int i = 1; i < sorted.Length; i++)
            {
                if (!sorted[i].Expired)
                {
                    header.AppendFormat("; {0}", sorted[i].ToString());
                }
            }

            AddHeader("Cookie", header.ToString());
        }