Example #1
0
        public void GetAllDontCombineSetCookie()
        {
            CombinedHttpHeaders headers = NewCombinedHttpHeaders();

            headers.Add(HttpHeaderNames.SetCookie, "a");
            headers.Add(HttpHeaderNames.SetCookie, "b");
            Assert.Equal(2, headers.GetAll(HttpHeaderNames.SetCookie).Count);
            Assert.Equal(new List <string>(new[] { "a", "b" }), headers.GetAll(HttpHeaderNames.SetCookie).Select(_ => _.ToString()).ToList());
        }
Example #2
0
        public void DontCombineSetCookieHeadersRegardlessOfCase()
        {
            CombinedHttpHeaders headers = NewCombinedHttpHeaders();

            headers.Add(AsciiString.Of("Set-Cookie"), "a");
            CombinedHttpHeaders otherHeaders = NewCombinedHttpHeaders();

            otherHeaders.Add(AsciiString.Of("set-cookie"), "b");
            otherHeaders.Add(AsciiString.Of("SET-COOKIE"), "c");
            headers.Add(otherHeaders);
            var list = headers.GetAll(HttpHeaderNames.SetCookie);

            Assert.Equal(3, headers.GetAll(HttpHeaderNames.SetCookie).Count);
        }
Example #3
0
        public void AddIterableCsvEmpty()
        {
            CombinedHttpHeaders headers = NewCombinedHttpHeaders();

            headers.Add(HeaderName, new List <ICharSequence>());
            Assert.Equal(0, headers.GetAll(HeaderName).Count);
        }
Example #4
0
        public void AddCharSequencesCsvWithValueContainingCommas()
        {
            CombinedHttpHeaders headers = NewCombinedHttpHeaders();

            headers.Add(HeaderName, HeaderValue.Eight.Subset(6));
            Assert.True(ContentEquals((StringCharSequence)HeaderValue.Eight.SubsetAsCsvString(6), headers.Get(HeaderName, null)));
            Assert.Equal(HeaderValue.Eight.Subset(6), headers.GetAll(HeaderName));
        }
Example #5
0
        public void DontCombineSetCookieHeaders()
        {
            CombinedHttpHeaders headers = NewCombinedHttpHeaders();

            headers.Add(HttpHeaderNames.SetCookie, "a");
            CombinedHttpHeaders otherHeaders = NewCombinedHttpHeaders();

            otherHeaders.Add(HttpHeaderNames.SetCookie, "b");
            otherHeaders.Add(HttpHeaderNames.SetCookie, "c");
            headers.Add(otherHeaders);
            Assert.Equal(3, headers.GetAll(HttpHeaderNames.SetCookie).Count);
        }
Example #6
0
        static void AssertCsvValues(CombinedHttpHeaders headers, HeaderValue headerValue)
        {
            Assert.True(ContentEquals(headerValue.AsCsv(), headers.Get(HeaderName, null)));

            List <ICharSequence>  expected = headerValue.AsList();
            IList <ICharSequence> values   = headers.GetAll(HeaderName);

            Assert.Equal(expected.Count, values.Count);
            for (int i = 0; i < expected.Count; i++)
            {
                Assert.True(expected[i].ContentEquals(values[i]));
            }
        }
Example #7
0
        public void OwsTrimming()
        {
            CombinedHttpHeaders headers = NewCombinedHttpHeaders();

            headers.Set(HeaderName, new List <ICharSequence> {
                (StringCharSequence)"\ta", (StringCharSequence)"   ", (StringCharSequence)"  b ", (StringCharSequence)"\t \t"
            });
            headers.Add(HeaderName, new List <ICharSequence> {
                (StringCharSequence)" c, d \t"
            });

            var expected = new List <ICharSequence> {
                (StringCharSequence)"a", (StringCharSequence)"", (StringCharSequence)"b", (StringCharSequence)"", (StringCharSequence)"c, d"
            };
            IList <ICharSequence> actual = headers.GetAll(HeaderName);

            Assert.True(expected.SequenceEqual(actual));
            Assert.Equal("a,,b,,\"c, d\"", headers.Get(HeaderName, null)?.ToString());

            Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)"a", true));
            Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)" a ", true));
            Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)"a", true));
            Assert.False(headers.ContainsValue(HeaderName, (StringCharSequence)"a,b", true));

            Assert.False(headers.ContainsValue(HeaderName, (StringCharSequence)" c, d ", true));
            Assert.False(headers.ContainsValue(HeaderName, (StringCharSequence)"c, d", true));
            Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)" c ", true));
            Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)"d", true));

            Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)"\t", true));
            Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)"", true));

            Assert.False(headers.ContainsValue(HeaderName, (StringCharSequence)"e", true));

            CombinedHttpHeaders copiedHeaders = NewCombinedHttpHeaders();

            copiedHeaders.Add(headers);
            Assert.Equal(new List <ICharSequence> {
                (StringCharSequence)"a", (StringCharSequence)"", (StringCharSequence)"b", (StringCharSequence)"", (StringCharSequence)"c, d"
            }, copiedHeaders.GetAll(HeaderName));
        }
Example #8
0
        public void GetAll()
        {
            CombinedHttpHeaders headers = NewCombinedHttpHeaders();

            headers.Set(HeaderName, new List <ICharSequence> {
                (StringCharSequence)"a", (StringCharSequence)"b", (StringCharSequence)"c"
            });
            var expected = new ICharSequence[] { (StringCharSequence)"a", (StringCharSequence)"b", (StringCharSequence)"c" };
            IList <ICharSequence> actual = headers.GetAll(HeaderName);

            Assert.True(expected.SequenceEqual(actual));

            headers.Set(HeaderName, new List <ICharSequence> {
                (StringCharSequence)"a,", (StringCharSequence)"b,", (StringCharSequence)"c,"
            });
            expected = new ICharSequence[] { (StringCharSequence)"a,", (StringCharSequence)"b,", (StringCharSequence)"c," };
            actual   = headers.GetAll(HeaderName);
            Assert.True(expected.SequenceEqual(actual));

            headers.Set(HeaderName, new List <ICharSequence> {
                (StringCharSequence)"a\"", (StringCharSequence)"b\"", (StringCharSequence)"c\""
            });
            expected = new ICharSequence[] { (StringCharSequence)"a\"", (StringCharSequence)"b\"", (StringCharSequence)"c\"" };
            actual   = headers.GetAll(HeaderName);
            Assert.True(expected.SequenceEqual(actual));

            headers.Set(HeaderName, new List <ICharSequence> {
                (StringCharSequence)"\"a\"", (StringCharSequence)"\"b\"", (StringCharSequence)"\"c\""
            });
            expected = new ICharSequence[] { (StringCharSequence)"a", (StringCharSequence)"b", (StringCharSequence)"c" };
            actual   = headers.GetAll(HeaderName);
            Assert.True(expected.SequenceEqual(actual));

            headers.Set(HeaderName, (StringCharSequence)"a,b,c");
            expected = new ICharSequence[] { (StringCharSequence)"a,b,c" };
            actual   = headers.GetAll(HeaderName);
            Assert.True(expected.SequenceEqual(actual));

            headers.Set(HeaderName, (StringCharSequence)"\"a,b,c\"");
            actual = headers.GetAll(HeaderName);
            Assert.True(expected.SequenceEqual(actual));
        }
Example #9
0
 static void AssertCsvValue(CombinedHttpHeaders headers, HeaderValue headerValue)
 {
     Assert.True(ContentEquals((StringCharSequence)headerValue.ToString(), headers.Get(HeaderName, null)));
     Assert.True(ContentEquals((StringCharSequence)headerValue.ToString(), headers.GetAll(HeaderName)[0]));
 }