示例#1
0
        public void ExportHeaderToStringCorrectly()
        {
            var entries = new HttpHeaderEntries();

            entries.Add("KEY1", "value1");
            entries.Add("KEY2", "value1");
            entries.Add("KEY2", "value2");
            var header = new HttpRequestHeader(
                "GET /myFile HTTP/1.1",
                entries);

            Assert.Equal(
                "GET /myFile HTTP/1.1\r\n"
                + "KEY1: value1\r\n"
                + "KEY2: value1\r\n"
                + "KEY2: value2\r\n\r\n"
                ,
                header.AsPlainText
                );
        }
示例#2
0
        public void CanRemoveHeaderKey()
        {
            var entries = new HttpHeaderEntries();

            entries.Add("KEY", "value");
            var header = new HttpRequestHeader(
                "GET /myFile HTTP/1.1",
                entries);

            header.Remove("KEY");
            Assert.False(header.ContainsKey("KEY"));
            Assert.False(header.ContainsKey("key"));
        }
示例#3
0
        public void HeaderKeysAreCaseInsensitive()
        {
            var entries = new HttpHeaderEntries();

            entries.Add("KEY", "value");
            var header = new HttpRequestHeader(
                "GET /myFile HTTP/1.1",
                entries);

            Assert.True(header.ContainsKey("key"));
            Assert.True(header.ContainsKey("KEY"));
            Assert.True(header.ContainsKey("KeY"));
            Assert.False(header.ContainsKey("KeY1"));
            Assert.False(header.ContainsKey(" key"));
            Assert.False(header.ContainsKey("key "));
            Assert.Equal("value", header.GetFirst("Key"));

            // overwrite the value, see if it confuses 'Key' vs 'KEY'
            header.Remove("KEY");
            header.Add("KEY", "newValue");
            Assert.Equal("newValue", header.GetFirst("Key"));
            Assert.Equal("newValue", header.GetFirst("KEY"));
        }