Example #1
0
        public void TestPathParameter()
        {
            SimpleUrl url;

            url = new SimpleUrl("http://dutc.com/a/{phone}/c");
            url.SetPathParameter("phone", "13010005000");
            Assert.AreEqual("/a/13010005000/c", url.Path);


            url = new SimpleUrl("http://dutc.com/a/{phone}/c/{phone}/");
            url.SetPathParameter("phone", "13010005000");
            Assert.AreEqual("/a/13010005000/c/13010005000/", url.Path);
        }
Example #2
0
        public HttpResponseMessage Post(HttpProxyRequestContext context)
        {
            HttpClient client       = new HttpClient();
            SimpleUrl  urlComponent = context.Url;

            foreach (var arg in context.Arguments)
            {
                if (arg.ArgType == HttpArgType.QueryString)
                {
                    urlComponent.SetParameter(arg.HttpArgName, arg.Value);
                }
            }
            string url = urlComponent.ToUrl();

            ///TODO body
            return(client.GetAsync(url).Result);
        }
Example #3
0
        public void TestHost()
        {
            SimpleUrl url;

            url = new SimpleUrl("http://dutc.com");
            Assert.AreEqual("dutc.com", url.Host);


            url = new SimpleUrl("https://localhost");
            Assert.AreEqual("localhost", url.Host);

            url = new SimpleUrl("https://127.0.0.1");
            Assert.AreEqual("127.0.0.1", url.Host);


            url = new SimpleUrl("https://{host}");
            Assert.AreEqual("{host}", url.Host);

            ////////////////////////////////
            url = new SimpleUrl("http://dutc.com/");
            Assert.AreEqual("dutc.com", url.Host);

            url = new SimpleUrl("https://localhost/");
            Assert.AreEqual("localhost", url.Host);

            url = new SimpleUrl("https://127.0.0.1/");
            Assert.AreEqual("127.0.0.1", url.Host);


            url = new SimpleUrl("https://{host}/");
            Assert.AreEqual("{host}", url.Host);

            ////////////////////////////////
            url = new SimpleUrl("http://dutc.com:8000/");
            Assert.AreEqual("dutc.com", url.Host);

            url = new SimpleUrl("https://localhost:8000/");
            Assert.AreEqual("localhost", url.Host);

            url = new SimpleUrl("https://127.0.0.1:8000/");
            Assert.AreEqual("127.0.0.1", url.Host);


            url = new SimpleUrl("https://{host}:8000/");
            Assert.AreEqual("{host}", url.Host);
        }
Example #4
0
        public void TestPort()
        {
            SimpleUrl url;

            url = new SimpleUrl("http://dutc.com");
            Assert.AreEqual(0, url.Port);


            url = new SimpleUrl("http://dutc.com/");
            Assert.AreEqual(0, url.Port);


            url = new SimpleUrl("http://dutc.com:80");
            Assert.AreEqual(80, url.Port);

            url = new SimpleUrl("http://dutc.com:80/");
            Assert.AreEqual(80, url.Port);
        }
        private HttpProxyRequestContext(HttpProxyContext proxyContext, object[] values, object client)
        {
            MethodInfo = proxyContext.MethodInfo;

            ///TODO:Clone
            Url         = proxyContext.Url.Clone();
            HttpMethod  = proxyContext.HttpMethod;
            ContentType = proxyContext.ContentType;
            Accept      = proxyContext.Accept;
            TimeOut     = proxyContext.TimeOut;
            Client      = client;

            this.Handler = new DefaultHttpHandler();

            Arguments = new List <HttpArgument>();
            for (int i = 0; i < values.Length; i++)
            {
                Arguments.Add(new HttpArgument(proxyContext.Arguments[i], values[i]));
            }
        }
Example #6
0
        public void TestAppendPath()
        {
            SimpleUrl url;

            url = new SimpleUrl("http://dutc.com/a/b/c");
            url.AppendPath("d/e/f");
            Assert.AreEqual(6, url.Paths.Count);
            Assert.AreEqual("/a/b/c/d/e/f", url.Path);


            url = new SimpleUrl("http://dutc.com/a/b/c");
            url.AppendPath("/d/e/f");
            Assert.AreEqual(6, url.Paths.Count);
            Assert.AreEqual("/a/b/c/d/e/f", url.Path);


            url = new SimpleUrl("http://dutc.com/a/b/c/");
            url.AppendPath("d/e/f");
            Assert.AreEqual(6, url.Paths.Count);
            Assert.AreEqual("/a/b/c/d/e/f", url.Path);


            url = new SimpleUrl("http://dutc.com/a/b/c/");
            url.AppendPath("/d/e/f");
            Assert.AreEqual(6, url.Paths.Count);
            Assert.AreEqual("/a/b/c/d/e/f", url.Path);


            url = new SimpleUrl("http://dutc.com/a/b/c?a=a");
            url.AppendPath("/d/e/f");
            Assert.AreEqual(6, url.Paths.Count);
            Assert.AreEqual("/a/b/c/d/e/f", url.Path);


            url = new SimpleUrl("http://dutc.com/a/b/c/?a=a");
            url.AppendPath("/d/e/f");
            Assert.AreEqual(6, url.Paths.Count);
            Assert.AreEqual("/a/b/c/d/e/f", url.Path);
        }
Example #7
0
        public void TestPathLength()
        {
            SimpleUrl url;

            url = new SimpleUrl("http://dutc.com/a/b/c");
            Assert.AreEqual(3, url.Paths.Count);
            Assert.AreEqual("/a/b/c", url.Path);


            url = new SimpleUrl("http://dutc.com/a/b/c/");
            Assert.AreEqual(4, url.Paths.Count);
            Assert.AreEqual("/a/b/c/", url.Path);


            url = new SimpleUrl("http://dutc.com/a/b/c?a=a");
            Assert.AreEqual(3, url.Paths.Count);
            Assert.AreEqual("/a/b/c", url.Path);


            url = new SimpleUrl("http://dutc.com/a/b/c/?a=a");
            Assert.AreEqual(4, url.Paths.Count);
            Assert.AreEqual("/a/b/c/", url.Path);
        }
Example #8
0
 public Builder SetUrl(SimpleUrl url)
 {
     context.Url = url;
     return(this);
 }