public void HeaderRemoval()
        {
            var         m = new DefaultHttpRequest(HttpVersion.Http11, HttpMethod.Get, "/");
            HttpHeaders h = m.Headers;

            // Insert sample keys.
            for (int i = 0; i < 1000; i++)
            {
                h.Set(HttpHeadersTestUtils.Of(i.ToString()), AsciiString.Empty);
            }

            // Remove in reversed order.
            for (int i = 999; i >= 0; i--)
            {
                h.Remove(HttpHeadersTestUtils.Of(i.ToString()));
            }

            // Check if random access returns nothing.
            for (int i = 0; i < 1000; i++)
            {
                Assert.False(h.TryGet(HttpHeadersTestUtils.Of(i.ToString()), out _));
            }

            // Check if sequential access returns nothing.
            Assert.True(h.IsEmpty);
        }
        public void GetOperations()
        {
            HttpHeaders headers = new DefaultHttpHeaders();
            headers.Add(HttpHeadersTestUtils.Of("Foo"), HttpHeadersTestUtils.Of("1"));
            headers.Add(HttpHeadersTestUtils.Of("Foo"), HttpHeadersTestUtils.Of("2"));

            Assert.Equal("1", headers.Get(HttpHeadersTestUtils.Of("Foo"), null));

            IList<ICharSequence> values = headers.GetAll(HttpHeadersTestUtils.Of("Foo"));
            Assert.Equal(2, values.Count);
            Assert.Equal("1", values[0].ToString());
            Assert.Equal("2", values[1].ToString());
        }
Example #3
0
        public void KeysShouldBeCaseInsensitiveInHeadersEquals()
        {
            var headers1 = new DefaultHttpHeaders();

            headers1.Add(HttpHeadersTestUtils.Of("name1"), new[] { "value1", "value2", "value3" });
            headers1.Add(HttpHeadersTestUtils.Of("nAmE2"), HttpHeadersTestUtils.Of("value4"));

            var headers2 = new DefaultHttpHeaders();

            headers2.Add(HttpHeadersTestUtils.Of("naMe1"), new[] { "value1", "value2", "value3" });
            headers2.Add(HttpHeadersTestUtils.Of("NAME2"), HttpHeadersTestUtils.Of("value4"));

            Assert.True(Equals(headers1, headers2));
            Assert.True(Equals(headers2, headers1));
            Assert.Equal(headers1.GetHashCode(), headers2.GetHashCode());
        }
Example #4
0
        public void StringKeyRetrievedAsAsciiString()
        {
            var headers = new DefaultHttpHeaders(false);

            // Test adding String key and retrieving it using a AsciiString key
            const string Connection = "keep-alive";

            headers.Add(HttpHeadersTestUtils.Of("Connection"), Connection);

            // Passes
            headers.TryGetAsString(HttpHeaderNames.Connection, out string value);
            Assert.NotNull(value);
            Assert.Equal(Connection, value);

            // Passes
            ICharSequence value2 = headers.Get(HttpHeaderNames.Connection, null);

            Assert.NotNull(value2);
            Assert.Equal(Connection, value2);
        }
Example #5
0
        public void KeysShouldBeCaseInsensitive()
        {
            var headers = new DefaultHttpHeaders();

            headers.Add(HttpHeadersTestUtils.Of("Name"), HttpHeadersTestUtils.Of("value1"));
            headers.Add(HttpHeadersTestUtils.Of("name"), HttpHeadersTestUtils.Of("value2"));
            headers.Add(HttpHeadersTestUtils.Of("NAME"), HttpHeadersTestUtils.Of("value3"));
            Assert.Equal(3, headers.Size);

            var values = new List <ICharSequence>
            {
                HttpHeadersTestUtils.Of("value1"),
                HttpHeadersTestUtils.Of("value2"),
                HttpHeadersTestUtils.Of("value3")
            };

            Assert.Equal(values, headers.GetAll(HttpHeadersTestUtils.Of("NAME")));
            Assert.Equal(values, headers.GetAll(HttpHeadersTestUtils.Of("name")));
            Assert.Equal(values, headers.GetAll(HttpHeadersTestUtils.Of("Name")));
            Assert.Equal(values, headers.GetAll(HttpHeadersTestUtils.Of("nAmE")));
        }