コード例 #1
0
        public void Headers_TransferEncodingChunked()
        {
            HttpResponseMessage message = new HttpResponseMessage();
            HttpResponseHeaders headers = message.Headers;

            Assert.IsNull(headers.TransferEncodingChunked, "#1");

            headers.TransferEncodingChunked = false;
            Assert.IsFalse(headers.TransferEncodingChunked.Value, "#2");

            headers.Clear();

            headers.TransferEncodingChunked = true;
            Assert.IsTrue(headers.TransferEncodingChunked.Value, "#3");
            Assert.AreEqual(1, headers.TransferEncoding.Count, "#3b");

            headers.Clear();
            Assert.IsTrue(headers.TryAddWithoutValidation("Transfer-Encoding", "value"), "#4-0");
//			Assert.AreEqual (false, headers.TransferEncodingChunked, "#4");

            headers.Clear();
            Assert.IsTrue(headers.TryAddWithoutValidation("Transfer-Encoding", "chunked"), "#5-0");
            Assert.AreEqual(true, headers.TransferEncodingChunked, "#5");

            message = new HttpResponseMessage();
            headers = message.Headers;
            Assert.IsTrue(headers.TryAddWithoutValidation("Transfer-Encoding", "ß"), "#6-0");
            Assert.IsNull(headers.TransferEncodingChunked, "#6");
        }
コード例 #2
0
        public void Headers_ConnectionClose()
        {
            HttpResponseMessage message = new HttpResponseMessage();
            HttpResponseHeaders headers = message.Headers;

            Assert.IsNull(headers.ConnectionClose, "#1");

            headers.ConnectionClose = false;
            Assert.IsFalse(headers.ConnectionClose.Value, "#2");

            headers.Clear();

            headers.ConnectionClose = true;
            Assert.IsTrue(headers.ConnectionClose.Value, "#3");

            headers.Clear();
            headers.Connection.Add("Close");
            Assert.IsTrue(headers.ConnectionClose.Value, "#4");
        }
コード例 #3
0
        public void Headers_Request()
        {
            HttpResponseMessage message = new HttpResponseMessage();
            HttpResponseHeaders headers = message.Headers;

            headers.Add("accept", "audio");
            Assert.AreEqual("audio", headers.GetValues("Accept").First(), "#1");

            headers.Clear();
            Assert.IsTrue(headers.TryAddWithoutValidation("accept", "audio"), "#2a");
            Assert.AreEqual("audio", headers.GetValues("Accept").First(), "#2");
        }
コード例 #4
0
ファイル: HttpResponseMessageTest.cs プロジェクト: N3X15/mono
        public void Headers_ConnectionClose()
        {
            HttpResponseMessage message = new HttpResponseMessage();
            HttpResponseHeaders headers = message.Headers;

            Assert.IsNull(headers.ConnectionClose, "#1");

            headers.ConnectionClose = false;
            Assert.IsFalse(headers.ConnectionClose.Value, "#2");

            headers.Clear();

            headers.ConnectionClose = true;
            Assert.IsTrue(headers.ConnectionClose.Value, "#3");

            headers.Clear();
            headers.Connection.Add("Close");
            Assert.IsTrue(headers.ConnectionClose.Value, "#4");

            Assert.AreEqual("StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: <null>, Headers:\r\n{\r\nConnection: Close\r\n}", message.ToString(), "#5");
        }
コード例 #5
0
        public void Headers_ConnectionClose()
        {
            HttpResponseMessage message = new HttpResponseMessage();
            HttpResponseHeaders headers = message.Headers;

            Assert.IsNull(headers.ConnectionClose, "#1");

            headers.ConnectionClose = false;
            Assert.IsFalse(headers.ConnectionClose.Value, "#2");

            headers.Clear();

            headers.ConnectionClose = true;
            Assert.IsTrue(headers.ConnectionClose.Value, "#3");

            headers.Clear();
            headers.Connection.Add("Close");
            Assert.IsTrue(headers.ConnectionClose.Value, "#4");

            // .NET encloses the "Connection: Close" with two whitespaces.
            var normalized = Regex.Replace(message.ToString(), @"\s", "");

            Assert.AreEqual("StatusCode:200,ReasonPhrase:'OK',Version:1.1,Content:<null>,Headers:{Connection:Close}", normalized, "#5");
        }
コード例 #6
0
        public void Header_BaseImplementation()
        {
            HttpResponseMessage message = new HttpResponseMessage();
            HttpResponseHeaders headers = message.Headers;

            headers.Add("a", "a-value");
            headers.Add("b", new List <string> {
                "v1", "v2"
            });
            headers.Add("c", null as string);
            headers.Add("d", new string[0]);

            headers.TryAddWithoutValidation("cache-control", "audio");

            Assert.IsFalse(headers.Contains("nn"), "#1a");
            Assert.IsTrue(headers.Contains("b"), "#1b");

            var values = headers.GetValues("b").ToList();

            Assert.AreEqual("v1", values[0], "#2a");
            Assert.AreEqual("v2", values[1], "#2b");

            Assert.IsFalse(headers.Remove("p"), "#3a");
            Assert.IsTrue(headers.Remove("b"), "#3b");
            Assert.IsFalse(headers.Contains("b"), "#3b-c");

            IEnumerable <string> values2;

            Assert.IsTrue(headers.TryGetValues("c", out values2));
            values = values2.ToList();
            Assert.AreEqual("", values[0], "#4a");

            int counter = 0;

            foreach (var i in headers)
            {
                ++counter;
            }

            Assert.AreEqual(3, counter, "#5");

            headers.Clear();
        }
コード例 #7
0
 private void SetErrorResponseHeaders(int statusCode)
 {
     StatusCode   = statusCode;
     ReasonPhrase = string.Empty;
     HttpResponseHeaders.Clear();
 }
コード例 #8
0
        public void Location_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
        {
            // just verify header names are compared using case-insensitive comparison.
            headers.TryAddWithoutValidation("LoCaTiOn", "  http://www.example.com/path/?q=v  ");
            Assert.Equal(new Uri("http://www.example.com/path/?q=v"), headers.Location);

            headers.Clear();
            headers.TryAddWithoutValidation("Location", "http://host");
            Assert.Equal(new Uri("http://host"), headers.Location);

            // This violates the RFCs, the Location header should be absolute.  However,
            // IIS and HttpListener do not enforce this requirement.
            headers.Clear();
            headers.Add("LoCaTiOn", "/relative/");
            Assert.Equal <Uri>(new Uri("/relative/", UriKind.Relative), headers.Location);
        }