Ejemplo n.º 1
0
        public object Request(HttpProxyRequestContext context)
        {
            HttpResponseMessage responseMessage;

            if (context.HttpMethod == Enum.HttpMethod.POST)
            {
                responseMessage = Post(context);
            }
            else
            {
                responseMessage = Get(context);
            }
            if (context.MethodInfo.ReturnType == typeof(HttpResponseMessage))
            {
                return(responseMessage);
            }
            if (responseMessage.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new Exception();
            }
            if (TypeUtils.IsModel(typeof(string)) == false)
            {
                return(responseMessage.Content.ReadAsStringAsync().Result);
            }

            return(null);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public object Request(HttpProxyContext proxyContext, object[] values, object client)
        {
            HttpProxyRequestContext context = GenerateContext(proxyContext, values, client);

            for (int i = 0; i < proxyContext.Filters.Count; i++)
            {
                var filter = proxyContext.Filters[i];
                filter.Before();
            }
            var result = context.Handler.Request(context);

            for (int i = proxyContext.Filters.Count - 1; i >= 0; i--)
            {
                var filter = proxyContext.Filters[i];
                filter.After();
            }

            if (proxyContext.MethodInfo.ReturnType == typeof(void))
            {
                return(null);
            }
            return(result);
        }