상속: IRequest
예제 #1
0
        public void Can_read_body_manually()
        {
            IRequest r = new Req { BodyString = "I am the posted body" };

            // grab some bytes ...
            byte[] bytes = new byte[5];
            IAsyncResult result = r.BeginReadBody(bytes, 0, 5, null, null); // no callback or state, we want to do this synchronously
            int bytesRead = r.EndReadBody(result); // this should block!  per: http://msdn.microsoft.com/en-us/library/ms228967(v=VS.80).aspx
            Assert.That(Encoding.UTF8.GetString(bytes), Is.EqualTo("I am "));

            // grab the rest
            byte[] moreBytes = new byte[1000];
            result = r.BeginReadBody(moreBytes, 5, 1000, null, null); // no callback or state, we want to do this synchronously
            bytesRead = r.EndReadBody(result); // this should block!  per: http://msdn.microsoft.com/en-us/library/ms228967(v=VS.80).aspx
            Assert.That(Encoding.UTF8.GetString(WithoutTrailingBytes(moreBytes)), Is.EqualTo("the posted body"));
        }
예제 #2
0
        public void Has_predicate_properties_for_checking_request_method_type()
        {
            Req r = new Req();

            r.Method = "GET";
            Assert.True(R(r).IsGet); Assert.False(R(r).IsPost); Assert.False(R(r).IsPut); Assert.False(R(r).IsDelete); Assert.False(R(r).IsHead);

            r.Method = "POST";
            Assert.False(R(r).IsGet); Assert.True(R(r).IsPost); Assert.False(R(r).IsPut); Assert.False(R(r).IsDelete); Assert.False(R(r).IsHead);

            r.Method = "PUT";
            Assert.False(R(r).IsGet); Assert.False(R(r).IsPost); Assert.True(R(r).IsPut); Assert.False(R(r).IsDelete); Assert.False(R(r).IsHead);

            r.Method = "DELETE";
            Assert.False(R(r).IsGet); Assert.False(R(r).IsPost); Assert.False(R(r).IsPut); Assert.True(R(r).IsDelete); Assert.False(R(r).IsHead);

            r.Method = "HEAD";
            Assert.False(R(r).IsGet); Assert.False(R(r).IsPost); Assert.False(R(r).IsPut); Assert.False(R(r).IsDelete); Assert.True(R(r).IsHead);
        }
예제 #3
0
        public void Can_get_the_value_of_a_POST_variable()
        {
            Req r = new Req();
            r.Headers["content-type"] = new string[] { "application/x-www-form-urlencoded" };

            r.BodyString = "";
            Assert.That(R(r).POST, Is.Empty);

            r.BodyString = "a=5";
            Assert.That(R(r).POST, Is.Not.Empty);
            Assert.That(R(r).POST["a"], Is.EqualTo("5"));
            Assert.That(R(r).POST["a"], Is.EqualTo("5"));
            Assert.That(R(r).POST["hi"], Is.Null);

            r.BodyString = "a=5&hi=there";
            Assert.That(R(r).POST["a"], Is.EqualTo("5"));
            Assert.That(R(r).POST["hi"], Is.EqualTo("there"));
        }
예제 #4
0
        public void Can_get_whether_or_not_the_request_has_form_data()
        {
            Req req = new Req { Method = "GET" };

            // if application/x-www-form-urlencoded
            req.Headers["content-type"] = new string[] { "application/x-www-form-urlencoded" };
            Assert.True(R(req).HasFormData);

            // if multipart/form-data
            req.Headers["content-type"] = new string[] { "multipart/form-data" };
            Assert.True(R(req).HasFormData);

            // if POST and no ContentType provided
            req.Method = "POST";
            req.Headers.Remove("content-type");
            Assert.True(R(req).HasFormData);

            // NO if a GET with no ContentType
            req.Method = "GET";
            Assert.False(R(req).HasFormData);

            // NO if a POST with a different Contenttype
            req.Method = "POST";
            req.Headers["content-type"] = new string[] { "text/html" };
            Assert.False(R(req).HasFormData);
        }
예제 #5
0
        public void Can_get_the_request_content_type()
        {
            Req req = new Req();
            req.Headers["content-type"] = new string[] { "text/html" };
            Assert.That(R(req).ContentType, Is.EqualTo("text/html"));

            req.Headers["content-type"] = new string[] { "text/plain" };
            Assert.That(R(req).ContentType, Is.EqualTo("text/plain"));

            req.Headers.Remove("content-type");
            Assert.Null(R(req).ContentType);
        }
예제 #6
0
        public void Can_get_the_value_of_a_POST_or_GET_variable_with_Params()
        {
            Req r = new Req { Uri = "/?foo=bar", Method = "POST" };
            r.BodyString = "a=1&b=2&hi=there";
            Request request = R(r);

            Assert.That(request.GET.Count,  Is.EqualTo(1));
            Assert.That(request.POST.Count, Is.EqualTo(3));
            Assert.That(request.Params.Count, Is.EqualTo(4));

            Assert.That(request.Params["foo"],     Is.EqualTo("bar"));
            Assert.That(request.Params["a"],       Is.EqualTo("1"));
            Assert.That(request.Params["b"],       Is.EqualTo("2"));
            Assert.That(request.Params["hi"],      Is.EqualTo("there"));
            Assert.That(request.Params["noExist"], Is.Null);
        }
예제 #7
0
 public void Can_get_the_path_info_which_is_the_Uri_without_querystrings()
 {
     Req request = new Req { Uri = "/foo/bar?hello=there" };
     request.Items["owin.base_path"] = "/foo.cgi/";
     Assert.That(R(request).PathInfo, Is.EqualTo("/foo/bar"));
 }
예제 #8
0
        public void Can_get_the_path_which_includes_the_base_name_and_path_without_querystrings( )
        {
            Req request = new Req { Uri = "/foo/bar?hello=there" };
            Assert.That(R(request).Path, Is.EqualTo("/foo/bar"));

            // includes base path
            request.Items["owin.base_path"] = "/foo.cgi";
            Assert.That(R(request).Path, Is.EqualTo("/foo.cgi/foo/bar"));
        }
예제 #9
0
        public void Can_get_scheme()
        {
            Req r = new Req();

            r.Items["owin.url_scheme"] = "http";
            Assert.That(R(r).Scheme, Is.EqualTo("http"));

            r.Items["owin.url_scheme"] = "https";
            Assert.That(R(r).Scheme, Is.EqualTo("https"));
        }
예제 #10
0
        public void Can_get_the_full_Url()
        {
            Req request = new Req { Uri = "/foo/bar?hi=there" };
            request.Items["owin.base_path"] = "/my/app";
            request.Items["owin.server_name"] = "localhost";
            request.Items["owin.server_port"] = 80;
            request.Items["owin.url_scheme"] = "http";
            Assert.That(R(request).Url, Is.EqualTo("http://localhost/my/app/foo/bar?hi=there"));

            request.Items["owin.base_path"] = "/my/root";
            Assert.That(R(request).Url, Is.EqualTo("http://localhost/my/root/foo/bar?hi=there"));

            request.Uri = "/neat";
            Assert.That(R(request).Url, Is.EqualTo("http://localhost/my/root/neat"));

            request.Items["owin.server_name"] = "code.com";
            Assert.That(R(request).Url, Is.EqualTo("http://code.com/my/root/neat"));

            request.Items["owin.url_scheme"] = "https";
            request.Items["owin.server_port"] = 443;
            Assert.That(R(request).Url, Is.EqualTo("https://code.com/my/root/neat"));

            request.Items["owin.server_port"] = 123;
            Assert.That(R(request).Url, Is.EqualTo("https://code.com:123/my/root/neat"));

            request.Items["owin.url_scheme"] = "http";
            Assert.That(R(request).Url, Is.EqualTo("http://code.com:123/my/root/neat"));
        }
예제 #11
0
        public void Can_get_protocol()
        {
            Req r = new Req();

            r.Items["owin.request_protocol"] = "HTTP/1.1";
            Assert.That(R(r).Protocol, Is.EqualTo("HTTP/1.1"));

            r.Items["owin.request_protocol"] = "HTTP/1.0";
            Assert.That(R(r).Protocol, Is.EqualTo("HTTP/1.0"));
        }
예제 #12
0
        public void Can_get_port()
        {
            Req r = new Req();

            r.Items.Remove("owin.server_port");
            Assert.That(R(r).Port, Is.EqualTo(0));

            r.Items["owin.server_port"] = "8080";
            Assert.That(R(r).Port, Is.EqualTo(8080));

            r.Items["owin.server_port"] = 1234;
            Assert.That(R(r).Port, Is.EqualTo(1234));
        }
예제 #13
0
        public void Can_get_IPEndPoint()
        {
            Req r = new Req();

            r.Items["owin.remote_endpoint"] = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 80);
            Assert.That(R(r).IPEndPoint.ToString(), Is.EqualTo("127.0.0.1:80"));

            r.Items["owin.remote_endpoint"] = new IPEndPoint(IPAddress.Parse("192.168.0.1"), 443);
            Assert.That(R(r).IPEndPoint.ToString(), Is.EqualTo("192.168.0.1:443"));
        }
예제 #14
0
        public void Can_get_host()
        {
            Req r = new Req();

            r.Items.Remove("owin.server_name");
            Assert.Null(R(r).Host);

            r.Items["owin.server_name"] = "localhost";
            Assert.That(R(r).Host, Is.EqualTo("localhost"));

            r.Items["owin.server_name"] = "google.com";
            Assert.That(R(r).Host, Is.EqualTo("google.com"));
        }
예제 #15
0
        public void Can_easily_get_the_string_value_for_a_Header_if_you_know_a_header_will_only_have_1_value()
        {
            Req r = new Req();
            r.Headers["content-type"] = new string[] { "text/plain" };

            Assert.That(R(r).Headers["content-type"], Is.EqualTo(new string[] { "text/plain" }));
            Assert.That(R(r).GetHeader("content-type"), Is.EqualTo("text/plain"));
        }