2020using System . Linq ;
2121using System . Text ;
2222using System . Threading . Tasks ;
23+ using Microsoft . AspNetCore . Http ;
2324using Microsoft . AspNetCore . Mvc ;
2425using Nethermind . JsonRpc ;
2526using Newtonsoft . Json ;
@@ -31,7 +32,6 @@ namespace Nethermind.Runner.Controllers
3132 [ ApiController ]
3233 public class MainController : ControllerBase
3334 {
34-
3535 private readonly IJsonRpcProcessor _jsonRpcProcessor ;
3636 private readonly JsonSerializerSettings _jsonSettings ;
3737
@@ -40,6 +40,7 @@ public MainController(IJsonRpcProcessor jsonRpcProcessor, IJsonRpcService jsonRp
4040 _jsonRpcProcessor = jsonRpcProcessor ;
4141 _jsonSettings = new JsonSerializerSettings
4242 {
43+ Formatting = Formatting . Indented ,
4344 ContractResolver = new CamelCasePropertyNamesContractResolver ( )
4445 } ;
4546
@@ -53,14 +54,15 @@ public MainController(IJsonRpcProcessor jsonRpcProcessor, IJsonRpcService jsonRp
5354 public ActionResult < string > Get ( ) => "Nethermind JSON RPC" ;
5455
5556 [ HttpPost ]
56- public async Task < JsonResult > Post ( )
57+ public async Task Post ( )
5758 {
5859 using ( var reader = new StreamReader ( Request . Body , Encoding . UTF8 ) )
5960 {
6061 var result = await _jsonRpcProcessor . ProcessAsync ( await reader . ReadToEndAsync ( ) ) ;
61- return result . IsCollection
62- ? new JsonResult ( result . Responses , _jsonSettings )
63- : new JsonResult ( result . Responses . SingleOrDefault ( ) , _jsonSettings ) ;
62+ var json = result . IsCollection
63+ ? JsonConvert . SerializeObject ( result . Responses , _jsonSettings )
64+ : JsonConvert . SerializeObject ( result . Responses . SingleOrDefault ( ) , _jsonSettings ) ;
65+ await Response . WriteAsync ( $ "{ json } \n ") ;
6466 }
6567 }
6668 }
0 commit comments