Ejemplo n.º 1
0
 public BrokerRConnectionBuilder WithHandler <T>(string path, RequestBodyHandler <T> handler)
 {
     return(WithHandler(path, async(request, cancellationToken) =>
     {
         var body = JsonSerializer.Deserialize <T>(request.Body);
         await handler(body, cancellationToken);
     }));
 }
Ejemplo n.º 2
0
 public IActionResult CreateOrUpdate([FromHeader] string username)
 {
     try
     {
         string body      = RequestBodyHandler.GetRawBodyString(HttpContext, new UTF8Encoding());
         Clinic newClinic = JsonConvert.DeserializeObject <Clinic>(body);
         ObjectsRepository.clinics[ObjectsRepository.clinics.FindIndex(x => x.Id.Equals(newClinic.Id))] = newClinic;
         return(Ok(ObjectsRepository.clinics.Find(x => x.Id.Equals(newClinic.Id))));
     }catch (Exception e)
     {
         return(BadRequest());
     }
 }
Ejemplo n.º 3
0
        public void HttpRequestReader_ParseWithContentLength()
        {
            var buffer = new MemoryStream(Encoding.UTF8.GetBytes(GetRequestTextWithContentLength()))
            {
                Position = 0
            };
            var parser = new RawHttpRequestReader(buffer, new HttpServerOptions());

            var request = parser.ReadAsync(CancellationToken.None).Result;

            var bodyReader = new RequestBodyHandler();

            Assert.IsTrue(request != null, "Parse failed.");
            Assert.AreEqual("Body123{}%!(:<>=", Encoding.UTF8.GetString(StreamToArray(request.Body)));
        }
Ejemplo n.º 4
0
 public BrokerROptions WithHandler <T>(string path, RequestBodyHandler <T> handler)
 {
     ConnectionBuilder.WithHandler(path, handler);
     return(this);
 }