Пример #1
0
        public void HttpBuilder_Test()
        {
            var httpBuilder = new HttpBuilder("/user", Method.GET, DataFormat.None);

            httpBuilder.Parameters = new List <Parameter>()
            {
                new Parameter("px", "px", ParameterType.UrlSegment)
            };

            httpBuilder.AddParameter(new Parameter("p1", "v1", ParameterType.HttpHeader));
            httpBuilder.AddParameter("p2", 22);
            httpBuilder.AddParameter("p3", 33m, ParameterType.QueryString);
            httpBuilder.AddFile("f1", "DotCommon.dll", "f1/contentType");
            httpBuilder.AddFile("f2", new byte[] { 1 }, "f2.txt", "f2/contentType");
            httpBuilder.AddFile("f3", w => { }, "f3.txt", 1, "f3/contentType");
            httpBuilder.AddFile(new FileParameter()
            {
                Name          = "f4",
                FileName      = "f4.txt",
                ContentLength = 101,
                ContentType   = "f4/contentType",
            });

            Assert.Contains(httpBuilder.Parameters, x => x.Name == "p1");
            Assert.Equal(Method.GET, httpBuilder.Method);
            Assert.Equal("/user", httpBuilder.Resource);
            Assert.Equal(4, httpBuilder.Files.Count);
            Assert.Equal(4, httpBuilder.Parameters.Count);
            Assert.Equal(DataFormat.None, httpBuilder.DataFormat);
        }
Пример #2
0
        /// <summary>创建HttpBuilder
        /// </summary>
        public override HttpBuilder CreateBuilder()
        {
            var builder = new HttpBuilder(Resource, Method.DELETE);

            builder.AddParameter("collection", Collection, ParameterType.QueryString);
            return(builder);
        }
Пример #3
0
        /// <summary>创建HttpBuilder
        /// </summary>
        public override HttpBuilder CreateBuilder()
        {
            var builder = new HttpBuilder(Resource, Method.GET);

            if (!Replication.IsNullOrWhiteSpace())
            {
                builder.AddParameter("replication", Replication, ParameterType.QueryString);
            }
            if (Count.HasValue)
            {
                builder.AddParameter("count", Count.Value, ParameterType.QueryString);
            }
            if (!DataCenter.IsNullOrWhiteSpace())
            {
                builder.AddParameter("dataCenter", DataCenter, ParameterType.QueryString);
            }
            if (!Ttl.IsNullOrWhiteSpace())
            {
                builder.AddParameter("ttl", Ttl, ParameterType.QueryString);
            }
            if (!Collection.IsNullOrWhiteSpace())
            {
                builder.AddParameter("collection", Collection, ParameterType.QueryString);
            }

            return(builder);
        }
Пример #4
0
        /// <summary>创建HttpBuilder
        /// </summary>
        public override HttpBuilder CreateBuilder()
        {
            var builder = new HttpBuilder(Resource, Method.DELETE);

            builder.AddParameter("fid", Fid, ParameterType.UrlSegment);
            return(builder);
        }
Пример #5
0
        public void HttpSafeBuilderBuildSpendAllTransactionWorks(ConnectionType propagationConnectionType)
        {
            Safe safe = Safe.Recover("cabbage drive wrestle fury goddess click riot mercy shy size error short", "",
                                     "foo", Network.TestNet);

            safe.DeleteWalletFile();
            var monitor = new HttpSafeMonitor(safe, 100);

            while (monitor.InitializationState != State.Ready)
            {
                Thread.Sleep(100);
            }
            Assert.True(monitor.GetSafeBalanceInfo().Balance > 0);

            var          httpSafeBuilder = new HttpSafeBuilder(monitor.Safe);
            const string toAddress       = "n16Yt8jpDf34nMbdJyZh1iqZkZFtAoLMbW";
            const string toPrivateKey    = "tprv8fAkYGDbNMNLLSWvmXshBiMQuEuEjt5ZMxiX1CNrV5hQCQLFqmpt3urpzrvgJHCwD7bJYMrSMcy8UPa4P3KnB84u2t4rZL874E79MRon4bU";

            var tx1 = httpSafeBuilder.BuildSpendAllTransaction(toAddress);

            Sender.Send(propagationConnectionType, tx1, tryTimes: 3);
            Assert.True(monitor.GetSafeBalanceInfo().Balance == 0);

            var httpBuilder = new HttpBuilder(monitor.Network);
            var tx2         = httpBuilder.BuildSpendAllTransaction(
                new List <string>
            {
                toPrivateKey
            },
                monitor.Safe.GetAddress(0));

            Sender.Send(propagationConnectionType, tx2, tryTimes: 3);
            Assert.True(monitor.GetSafeBalanceInfo().Balance > 0);
        }
Пример #6
0
        public void Handle(HttpDiscussion discussion)
        {
            var url_part = discussion.Request.Url;

            // do some basic sanitization of the URL, attempting to make sure they can't read files outside the basepath
            // NOTE: this is probably not bulletproof/secure
            url_part = url_part.Replace("\\..\\", "\\");
            url_part = url_part.Replace("/../", "/");
            url_part = url_part.Replace("//", "/");
            url_part = url_part.Replace(@"\\", @"\");
            url_part = url_part.Replace(":", "");
            url_part = url_part.Replace("/", Path.DirectorySeparatorChar.ToString());

            foreach (var file in FilesPath)
            {
                if (file.Path == url_part)
                {
                    var file_extension = GetExtension(url_part);

                    discussion.Response                         = new HttpResponse();
                    discussion.Response.StatusCode              = "200";
                    discussion.Response.ReasonPhrase            = "Ok";
                    discussion.Response.Headers["Content-Type"] = QuickMimeTypeMapper.GetMimeType(file_extension);
                    discussion.Response.Content                 = file.Content;

                    return;
                }
            }

            discussion.Response = HttpBuilder.NotFound();
        }
Пример #7
0
        private static HttpResponse RunScripts(HttpRequest request)
        {
            string content = request.Content;
            bool   error   = false;

            Script[] scripts = ExtractScripts(content);
            foreach (Script script in scripts)
            {
                RunScript(script);
                error = error || script.exception != null;
            }

            HttpResponse response = null;

            if (error == true)
            {
                response = HttpBuilder.ExpectationFailed();
            }
            else
            {
                response = HttpBuilder.OK();
            }

            return(response);
        }
Пример #8
0
        public ActionResult FindPatientsByID(string id)
        {
            HttpBuilder             builder      = new HttpBuilder();
            string                  jsonResponse = builder.GetResponse(id.ToString());
            BookingAppointmentModel model        = JsonConvert.DeserializeObject <BookingAppointmentModel>(jsonResponse);

            return(View("~/Views/Appointment/Index.cshtml", model));
        }
        public void Build_SetsUriOnRequest()
        {
            var builder = new HttpBuilder(new HttpClient());

            var request = builder.Build(HttpMethod.Options, _uri);

            request.RequestUri.Should().Be(_uri);
        }
        public void Build_SetsContentOnRequest()
        {
            var builder = new HttpBuilder(new HttpClient());
            builder.Content(new { Name = "Sergej Popov" });

            var request = builder.Build(HttpMethod.Get, _uri);

            request.Content.ReadAsStringAsync().Result.Should().Be("{\"Name\":\"Sergej Popov\"}");
        }
        public void Build_SetsMethodOnRequest()
        {
            var builder = new HttpBuilder(new HttpClient());
            var method = HttpMethod.Trace;

            var request = builder.Build(method, _uri);

            request.Method.Should().Be(method);
        }
Пример #12
0
        private void btn_RequestTest_Click(object sender, EventArgs e)
        {
            var request = ValidateRequestParameter();

            if (request != null)
            {
                var response = HttpBuilder.Handle(request);
                TestConsoleLog(response);
            }
        }
        public void Build_SetsRequestHeaderOnRequest()
        {
            var date = DateTime.UtcNow;
            var builder = new HttpBuilder(new HttpClient());
            builder.Headers(headers => headers.Date = date);

            var request = builder.Build(HttpMethod.Options, _uri);

            request.Headers.Date.Should().Be(date);
        }
        public void Build_SetsMimeOnRequest()
        {
            var builder = new HttpBuilder(new HttpClient());
            builder.Content(new { Name = "Sergej Popov" });
            builder.Mime(Mime.ImagePng);

            var request = builder.Build(HttpMethod.Options, _uri);

            request.Content.Headers.ContentType.Should().Be(MediaTypeHeaderValue.Parse(Mime.ImagePng.GetAlias()));
        }
        /// <summary>创建HttpBuilder
        /// </summary>
        public override HttpBuilder CreateBuilder()
        {
            var builder = new HttpBuilder(Resource, Method.GET);

            if (GarbageThreshold.HasValue)
            {
                builder.AddParameter("garbageThreshold", GarbageThreshold, ParameterType.QueryString);
            }

            return(builder);
        }
        public void Build_SetsContentHeaderOnRequest()
        {
            const long length = 123L;
            var builder = new HttpBuilder(new HttpClient());
            builder.Content(new { Name = "Sergej Popov" });
            builder.Headers(headers => headers.ContentLength = length);

            var request = builder.Build(HttpMethod.Options, _uri);

            request.Content.Headers.ContentLength.Should().Be(length);
        }
Пример #17
0
        /// <summary>创建HttpBuilder
        /// </summary>
        public override HttpBuilder CreateBuilder()
        {
            var builder = new HttpBuilder(Resource, Method.GET);

            builder.AddParameter("fileId", Fid, ParameterType.QueryString);
            if (IsRead.HasValue)
            {
                if (IsRead.Value)
                {
                    builder.AddParameter("read", "yes", ParameterType.QueryString);
                }
            }
            return(builder);
        }
Пример #18
0
        /// <summary>创建HttpBuilder
        /// </summary>
        public override HttpBuilder CreateBuilder()
        {
            var builder = new HttpBuilder(Resource, Method.GET);

            if (!VolumeId.IsNullOrWhiteSpace())
            {
                builder.AddParameter("volumeId", VolumeId, ParameterType.QueryString);
            }
            if (!Collection.IsNullOrWhiteSpace())
            {
                builder.AddParameter("collection", Collection, ParameterType.QueryString);
            }
            return(builder);
        }
Пример #19
0
        private HttpResponse HomeIndex(HttpRequest request)
        {
            //try
            //{
            //    if (request.Content != null)
            //    {
            //        WmsModel model = JsonConvert.DeserializeObject<WmsModel>(request.Content);
            //        HttpResponse response;
            //        switch (model.Task_type)
            //        {
            //            case WmsStatus.StockInTask:
            //                response = CheckWmsModel(model, WmsStatus.StockCheckTask, false);
            //                break;
            //            case WmsStatus.StockOutTask:
            //                response = CheckWmsModel(model, WmsStatus.StockCheckTask, false);
            //                break;
            //            case WmsStatus.StockMoveTask:
            //                response = CheckWmsModel(model, WmsStatus.StockCheckTask, false);
            //                break;
            //        }
            //        if (response != null) return response;
            //        if (!WmsModelAdd(model, out string result))
            //        {
            //            return FailResponse(result);
            //        }
            //        return OkResponse();
            //    }
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e.Message);
            //}
            return(HttpBuilder.NotFound());
            //string value = "";
            //if (request.Headers.ContainsKey("WMS_DATA"))
            //{
            //    value = request.Headers["WMS_DATA"];
            //}

            //return new HttpResponse()
            //{
            //    ContentAsUTF8 = "{\"data\":\""+ value
            //        +"\",\"name\":\"kyle\",\"age\":18,\"friend\":[{\"name\":\"matt\",\"sex\":\"man\"},{\"name\":\"butt\",\"sex\":\"man\"}]}",
            //    ReasonPhrase = "OK",
            //    StatusCode = "200"
            //};
        }
Пример #20
0
        private HttpResponse HomeIndex(HttpRequest request)
        {
            return(HttpBuilder.NotFound());
            //string value = "";
            //if (request.Headers.ContainsKey("WMS_DATA"))
            //{
            //    value = request.Headers["WMS_DATA"];
            //}

            //return new HttpResponse()
            //{
            //    ContentAsUTF8 = "{\"data\":\""+ value
            //        +"\",\"name\":\"kyle\",\"age\":18,\"friend\":[{\"name\":\"matt\",\"sex\":\"man\"},{\"name\":\"butt\",\"sex\":\"man\"}]}",
            //    ReasonPhrase = "OK",
            //    StatusCode = "200"
            //};
        }
        public HttpResponse Handle(HttpRequest request)
        {
            var url_part = request.GetPath();

            //read everything before query params start
            if (url_part.Contains("?"))
            {
                url_part = url_part.Substring(0, url_part.IndexOf("?"));
            }

            // do some basic sanitization of the URL, attempting to make sure they can't read files outside the basepath
            // NOTE: this is probably not bulletproof/secure
            url_part = url_part.Replace("\\..\\", "\\");
            url_part = url_part.Replace("/../", "/");
            url_part = url_part.Replace("//", "/");
            url_part = url_part.Replace(@"\\", @"\");
            url_part = url_part.Replace(":", "");
            url_part = url_part.Replace("/", Path.DirectorySeparatorChar.ToString());

            // make sure the first part of the path is not
            if (url_part.Length > 0)
            {
                var first_char = url_part.ElementAt(0);
                if (first_char == '/' || first_char == '\\')
                {
                    url_part = "." + url_part;
                }
            }
            var local_path = Path.Combine(this.BasePath, url_part);

            if (ShowDirectories && Directory.Exists(local_path))
            {
                // Console.WriteLine("FileSystemRouteHandler Dir {0}",local_path);
                return(Handle_LocalDir(request, local_path));
            }
            else if (File.Exists(local_path))
            {
                // Console.WriteLine("FileSystemRouteHandler File {0}", local_path);
                return(Handle_LocalFile(request, local_path));
            }
            else
            {
                return(HttpBuilder.NotFound());
            }
        }
Пример #22
0
        /// <summary>创建HttpBuilder
        /// </summary>
        public override HttpBuilder CreateBuilder()
        {
            var builder = new HttpBuilder("/submit", Method.POST);

            if (!FilePath.IsNullOrWhiteSpace())
            {
                builder.AddFile("file", FilePath);
            }
            if (FileBytes != null && FileBytes.Length > 0)
            {
                builder.AddFile("file", FileBytes, FileName);
            }
            if (Writer != null)
            {
                builder.AddFile("file", Writer, FileName, ContentLength.Value);
            }
            return(builder);
        }
Пример #23
0
        public static HttpResponse Get(HttpRequest request)
        {
            if (!request.GetParams.ContainsKey("user_id") || !request.GetParams.ContainsKey("sum"))
            {
                return(HttpBuilder.NotFound());
            }

            if (!long.TryParse(request.GetParams["user_id"], out var userId))
            {
                return(HttpBuilder.NotFound());
            }
            if (!float.TryParse(request.GetParams["sum"], out var sum))
            {
                return(HttpBuilder.NotFound());
            }

            if (userId == 0 || Math.Abs(sum) < 1)
            {
                return(HttpBuilder.NotFound());
            }

            Payments.Payment payment = Payments.CreatePayment(userId, sum, Payments.Type.Income);
            if (payment.PaymentId == 0)
            {
                return(HttpBuilder.NotFound());
            }

            // Получение параметров
            var data = Interkassa.GetDefaultData(payment.PaymentId, payment.Sum);

            // Добавляем в конец параметров ключ по которому будет высчитан хэш
            data.Add("ik_sign", Interkassa.SecretKey);
            var sign = Interkassa.GetEncodedSign(data.Values.ToArray());

            // Заменяем ключ на хэш
            data["ik_sign"] = sign;

            return(new HttpResponse()
            {
                ContentAsUTF8 = Interkassa.GetForm(data),
                ReasonPhrase = "OK",
                StatusCode = "200"
            });
        }
        public void Build_Throws_WhenContentNotSet_AndMimeTypeIsSet()
        {
            var builder = new HttpBuilder(new HttpClient());
            builder.Mime(Mime.ImagePng);

            var request = builder.Build(HttpMethod.Options, _uri);
        }
        public void Build_Throws_WhenContentNotSet_AndContentHeaderIsSet()
        {
            var builder = new HttpBuilder(new HttpClient());
            builder.Headers(headers => { headers.ContentLanguage.Add("en-GB"); });

            var request = builder.Build(HttpMethod.Options, _uri);
        }
        public void Build_SetsTimeoutOnClient()
        {
            var timeout = TimeSpan.FromSeconds(15);
            var builder = new HttpBuilder(new HttpClient());
            builder.Timeout(timeout);

            builder.Build(HttpMethod.Head, _uri);

            builder.Client.Timeout.Should().Be(timeout);
        }
        public void Build_SetsVersionOnRequest()
        {
            var version = new Version(1, 1);
            var builder = new HttpBuilder(new HttpClient());
            builder.Version(version);

            var request = builder.Build(HttpMethod.Options, _uri);

            request.Version.Should().Be(version);
        }
Пример #28
0
 public HttpResponse SendEmail(HttpRequest request)
 {
     return(HttpBuilder.MovedPermanently("/"));
 }
Пример #29
0
        /// <summary>创建HttpBuilder
        /// </summary>
        public override HttpBuilder CreateBuilder()
        {
            var builder = new HttpBuilder(Resource, Method.GET);

            return(builder);
        }