Exemplo n.º 1
0
 public void head_from_common_site()
 {
     var rq = new HttpRequestBuilder().Head(new Uri("http://xkcd.com/1269/")).Build();
     using (var result = _subject.Request(rq))
     {
         Assert.That(result.StatusCode == 200);
     }
 }
Exemplo n.º 2
0
 public void head_from_wikipedia()
 {
     var rq = new HttpRequestBuilder().Head(new Uri("http://en.wikipedia.org/wiki/Ternary_search_tree")).Build();
     using (var result = _subject.Request(rq))
     {
         Assert.That(result.StatusCode == 200);
     }
 }
Exemplo n.º 3
0
        public void connection_to_rabbit_mq_api()
        {
            var rq = new HttpRequestBuilder().Get(new Uri("http://localhost:15672/api/overview")).BasicAuthentication("guest", "guest").Build();
            using (var result = _subject.Request(rq))
            {
                var body = result.BodyReader.ReadStringToLength();

                Console.WriteLine(body);
                Assert.That(body, Contains.Substring("{\"management_version"));
            }
        }
Exemplo n.º 4
0
        public void head_from_wikipedia()
        {
            var rq = new HttpRequestBuilder().Head(new Uri("http://en.wikipedia.org/wiki/Ternary_search_tree")).Build();
            using (var result = _subject.Request(rq))
            {
                var body = result.BodyReader.ReadStringToLength();

                Console.WriteLine(body);
                Assert.That(result.StatusCode == 200);
                Assert.That(body, Is.Empty);
            }
        }
Exemplo n.º 5
0
        public void read_from_nuget()
        {
            var rq = new HttpRequestBuilder().Get(new Uri("https://www.nuget.org/")).Build();
            using (var result = _subject.Request(rq))
            {
                Assert.That(result.StatusClass, Is.EqualTo(StatusClass.Success), result.StatusMessage);
                var body = result.BodyReader.ReadStringToLength();

                Console.WriteLine("Expected " + result.BodyReader.ExpectedLength + ", got " + body.Length);
                Console.WriteLine(body);
                Assert.That(body, Contains.Substring("<html"));
            }
        }
Exemplo n.º 6
0
        public void correctly_sends_query_strings()
        {
            var rq = new HttpRequestBuilder().Get(new Uri("http://www.google.co.uk/?q=wipquazin")).Build();
            using (var result = _subject.Request(rq))
            {
                var body = result.BodyReader.ReadStringToLength();

                Console.WriteLine(Write(result.Headers));
                Console.WriteLine(body);

                Assert.That(body, Contains.Substring("wipquazin"));
            }
        }
Exemplo n.º 7
0
        public void can_read_chunked_responses_as_one_complete_response()
        {
            var rq = new HttpRequestBuilder().Get(new Uri("http://www.httpwatch.com/httpgallery/chunked/")).Build();
            using (var result = _subject.Request(rq))
            {
                var reader = result.BodyReader;

                var body = reader.ReadStringToLength();

                Console.WriteLine(Write(result.Headers));
                Console.WriteLine(body);

                Assert.That(result.StatusMessage, Is.EqualTo("OK"));
                Assert.That(body, Contains.Substring("<html"));
                Assert.That(body, Contains.Substring("</html>"));
            }
        }
        public void can_use_crossload_feature()
        {
            _client.Request(_putRq).Dispose(); // put a file in place

            var load = new HttpRequestBuilder().Get(_uri_src).Build();
            var store = new HttpRequestBuilder().Put(_uri_dst);

            _client.CrossLoad(load, store); // copy from src to dest

            var getRq = new HttpRequestBuilder().Get(_uri_dst).Build();
            using (var result = _client.Request(getRq)) // check dest is correct
            {
                var body = result.BodyReader.ReadStringToLength();
                Assert.That(body, Is.EqualTo("Hello, world"));
            }
            _client.Request(_deleteRq).Dispose();
            _client.Request(_deleteRq2).Dispose();
        }
Exemplo n.º 9
0
        public void leak_test_over_result_object()
        {
            var start = Connections();
            var rq = new HttpRequestBuilder().Get(new Uri("http://localhost:55672/api/vhosts")).BasicAuthentication("guest", "guest").Build();
            for (int i = 0; i < 512; i++)
            {
                using (var result = _subject.Request(rq))
                {
                    Assert.That(start, Is.Not.EqualTo(Connections()));
                    Console.WriteLine(result.BodyReader.ReadStringToLength());
                }
            }
            Thread.Sleep(500);
            var end = Connections();

            Console.WriteLine("Before: " + start + ", after: " + end);
            Assert.That(end, Is.LessThanOrEqualTo(start));
        }
Exemplo n.º 10
0
        public void can_pump_a_stream_from_a_get_to_a_put()
        {
            _client.Request(_putRq).Dispose();
            using (var getTx = _client.Request(_getRq)) // get source
            {
                var putRq = new HttpRequestBuilder().Put(_uri_dst)
                    .Build(getTx.RawBodyStream, getTx.BodyReader.ExpectedLength);
                using (var putTx = _client.Request(putRq)) // write out to dest
                {
                    Assert.That(putTx.StatusClass, Is.EqualTo(StatusClass.Success));
                }

                var getRq = new HttpRequestBuilder().Get(_uri_dst).Build();
                using (var result = _client.Request(getRq)) // check dest is correct
                {
                    var body = result.BodyReader.ReadStringToLength();
                    Assert.That(body, Is.EqualTo("Hello, world"));
                }
            }
            _client.Request(_deleteRq).Dispose();
            _client.Request(_deleteRq2).Dispose();
        }
Exemplo n.º 11
0
        public void read_from_wikipedia()
        {
            var rq = new HttpRequestBuilder().Get(new Uri("http://en.wikipedia.org/wiki/Ternary_search_tree")).Build();
            using (var result = _subject.Request(rq))
            {
                var body = result.BodyReader.ReadStringToLength();

                Console.WriteLine(Write(result.Headers));
                Console.WriteLine(body);

                Assert.That(result.StatusMessage, Is.EqualTo("OK"));
                Assert.That(body, Contains.Substring("<html"));
            }
        }
Exemplo n.º 12
0
        public void can_use_crossload_with_hash_feature()
        {
            _client.Request(_putRq).Dispose(); // put a file in place

            var load = new HttpRequestBuilder().Get(_uri_src).Build();
            var store = new HttpRequestBuilder().Put(_uri_dst);

            var hash = _client.CrossLoad(load, store, "MD5"); // copy from src to dest

            Assert.That(string.Join("", hash.Select(h=>h.ToString("x"))),
                Is.EqualTo("bc6e6f16b8a077ef5fbc8d59d0b931b9"));

            var getRq = new HttpRequestBuilder().Get(_uri_dst).Build();
            using (var result = _client.Request(getRq)) // check dest is correct
            {
                var body = result.BodyReader.ReadStringToLength();
                Assert.That(body, Is.EqualTo("Hello, world"));
            }
            _client.Request(_deleteRq).Dispose();
            _client.Request(_deleteRq2).Dispose();
        }
        public void Request_builder_changes_content_type_for_form_data()
        {
            var request =  new HttpRequestBuilder().Put(new Uri("http://test")).BuildForm(new {});

            Assert.That(request.RequestHead, Contains.Substring("\r\nContent-Type: application/x-www-form-urlencoded\r\n"));
        }
Exemplo n.º 14
0
        public void read_from_iana()
        {
            var rq = new HttpRequestBuilder().Get(new Uri("http://www.iana.org/domains/reserved")).Build();
            using (var result = _subject.Request(rq))
            {
                var body = result.BodyReader.ReadStringToLength();

                Console.WriteLine(Write(result.Headers));

                Console.WriteLine("Expected " + result.BodyReader.ExpectedLength + ", got " + body.Length);
                Console.WriteLine(body);
                Assert.That(body, Contains.Substring("<html"));
                Assert.That(body, Contains.Substring("</html>"), "didn't read to end");
                Assert.That(result.BodyReader.Complete, Is.True, "reader did not complete");

                // this server returns an invalid length!
                Assert.That(result.BodyReader.ExpectedLength, Is.GreaterThanOrEqualTo(body.Length), "length was not correct");
            }
        }
Exemplo n.º 15
0
        public void read_from_common_site()
        {
            var rq = new HttpRequestBuilder().Get(new Uri("http://xkcd.com/1269/")).Build();
            using (var result = _subject.Request(rq))
            {
                var body = result.BodyReader.ReadStringToLength();

                Console.WriteLine(Write(result.Headers));
                Console.WriteLine(body);

                Assert.That(result.StatusMessage, Is.EqualTo("OK"));
                Assert.That(body, Contains.Substring("<html"));
            }
        }
Exemplo n.º 16
0
        public void reading_the_body_of_a_head_request_results_in_a_timeout()
        {
            var rq = new HttpRequestBuilder().Head(new Uri("http://xkcd.com/1269/")).Build();

            _subject.Timeout = TimeSpan.FromSeconds(0.5);

            using (var result = _subject.Request(rq))
            {
                var exception = Assert.Throws<Http.TimeoutException>(() => result.BodyReader.ReadStringToLength());
                Assert.That(exception.ErrorCode, Is.EqualTo((int)SocketError.TimedOut));
            }
        }
Exemplo n.º 17
0
        public void read_from_iana()
        {
            var rq = new HttpRequestBuilder().Get(new Uri("http://www.iana.org/domains/example")).Build();
            using (var result = _subject.Request(rq))
            {
                var body = result.BodyReader.ReadStringToTimeout(); // this server returns an invalid length!

                Console.WriteLine("Expected " + result.BodyReader.ExpectedLength + " but got " + body.Length);
                Console.WriteLine(body);
                Assert.That(body, Contains.Substring("<html"));
            }
        }
Exemplo n.º 18
0
        public void leak_test_anti_test()
        {
            var start = Connections();
            var rq = new HttpRequestBuilder().Get(new Uri("http://localhost:15672/api/vhosts")).BasicAuthentication("guest", "guest").Build();
            for (int i = 0; i < 110; i++)
            {
                var result = _subject.Request(rq);
                /*using (*/
                var stream = result.BodyReader;/*)*/
                {
                    Assert.That(start, Is.Not.EqualTo(Connections()));
                    Console.WriteLine(stream.ReadStringToLength());
                }
            }
            Thread.Sleep(500);
            var end = Connections();

            Console.WriteLine("Before: " + start + ", after: " + end);
            Assert.That(end, Is.GreaterThan(start));
        }
Exemplo n.º 19
0
        public void leak_test_over_cross_load()
        {
            var start = Connections();

            _client.Request(_putRq).Dispose(); // put a file in place
            var load = new HttpRequestBuilder().Get(_uri_src).Build();
            var store = new HttpRequestBuilder().Put(_uri_dst);

            for (int i = 0; i < 51; i++) // WebDAV is very slow... don't do too many!
            {
                _client.CrossLoad(load, store); // copy from src to dest
            }
            _client.Request(_deleteRq).Dispose();
            _client.Request(_deleteRq2).Dispose();

            Thread.Sleep(1000);
            var end = Connections();

            Console.WriteLine("Before: " + start + ", after: " + end);
            Assert.That(end, Is.LessThanOrEqualTo(start));
        }