diff --git a/ln.http.service/Program.cs b/ln.http.service/Program.cs
index ef18911..41c8b75 100644
--- a/ln.http.service/Program.cs
+++ b/ln.http.service/Program.cs
@@ -11,7 +11,7 @@ namespace ln.http.service
static void Main(string[] args)
{
StaticRouter staticRouter = new StaticRouter(".");
- HTTPServer httpServer = new HTTPServer(new HttpListener(8888), new LoggingRouter(staticRouter));
+ HTTPServer httpServer = new HTTPServer(new HttpListener(8888), new LoggingRouter(staticRouter.Route).Route);
httpServer.Start();
diff --git a/ln.http.tests/UnitTest1.cs b/ln.http.tests/UnitTest1.cs
index 6f29432..629cac4 100644
--- a/ln.http.tests/UnitTest1.cs
+++ b/ln.http.tests/UnitTest1.cs
@@ -2,7 +2,9 @@ using System;
using System.IO;
using System.Net;
using System.Net.Http;
+using System.Net.Http.Headers;
using ln.http.router;
+using ln.json;
using ln.type;
using NUnit.Framework;
@@ -20,11 +22,12 @@ namespace ln.http.tests
return;
HttpRouter testRouter = new HttpRouter();
+ testRouter.Map(HttpMethod.ANY, "/controller/*", HttpRoutePriority.NORMAL, new TestApiController().Route);
StaticRouter staticRouter = new StaticRouter(AppContext.BaseDirectory);
- testRouter.AddSimpleRoute("/static/*", staticRouter);
+ testRouter.Map(HttpMethod.ANY, "/static/*", staticRouter.Route);
- server = new HTTPServer(testRouter);
+ server = new HTTPServer(testRouter.Route);
server.AddEndpoint(new Endpoint(IPv6.ANY,0));
server.Start();
@@ -50,5 +53,34 @@ namespace ln.http.tests
Assert.Pass();
}
+
+ [Test]
+ public void TestPutJson()
+ {
+ JSONObject jsonPutObject = new JSONObject();
+ jsonPutObject["PutTest"] = JSONTrue.Instance;
+ StringContent jsonStringContent = new StringContent(jsonPutObject.ToString());
+ jsonStringContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
+
+ HttpClient client = new HttpClient();
+ HttpResponseMessage response = client.PutAsync(String.Format("http://localhost:{0}/controller/put", testPort), jsonStringContent).Result;
+
+ Assert.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode);
+ Assert.Pass();
+ }
+ }
+
+ class TestApiController : HttpEndpointController
+ {
+ [Map(HttpMethod.PUT, "/put")]
+ public HttpResponse PutTest(
+ [HttpArgumentSource(HttpArgumentSource.CONTENT)]
+ JSONObject jObject
+ )
+ {
+ if (jObject.ContainsKey("PutTest") && jObject["PutTest"] is JSONTrue jsonTrue && jsonTrue == JSONTrue.Instance)
+ return HttpResponse.OK();
+ return HttpResponse.BadRequest();
+ }
}
}
\ No newline at end of file
diff --git a/ln.http/HttpEndpointController.cs b/ln.http/HttpEndpointController.cs
index 5291fe1..b251f43 100644
--- a/ln.http/HttpEndpointController.cs
+++ b/ln.http/HttpEndpointController.cs
@@ -96,7 +96,15 @@ namespace ln.http
contentType.Equals("application/json"))
{
using (TextReader reader = httpContext.Request.ContentStream.TextReader())
- parameters[n] = JSONMapper.DefaultMapper.FromJson(JSONParser.Parse(reader), _parameterInfos[n].ParameterType);
+ {
+ JSONValue jsonValue = JSONParser.Parse(reader);
+
+ if (typeof(JSONValue).IsAssignableFrom(_parameterInfos[n].ParameterType))
+ parameters[n] = jsonValue;
+ else
+ parameters[n] = JSONMapper.DefaultMapper.FromJson(jsonValue,
+ _parameterInfos[n].ParameterType);
+ }
}
}
else if (_parameterInfos[n].HasDefaultValue)
diff --git a/ln.http/ln.http.csproj b/ln.http/ln.http.csproj
index 9d46335..b6993e3 100644
--- a/ln.http/ln.http.csproj
+++ b/ln.http/ln.http.csproj
@@ -10,7 +10,7 @@
(c) 2020 Harald Wolff-Thobaben
http server
9
- 0.5.0
+ 0.5.1
@@ -18,7 +18,7 @@
-
+