Skip to content

Commit

Permalink
Fix: OrchardCMS#5533 - Enabled reading request body for HTTP POST req…
Browse files Browse the repository at this point in the history
…uests.
  • Loading branch information
emrah.tokalak committed Jun 12, 2023
1 parent 3e937ab commit 329ac70
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Text;
using System.IO;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
Expand Down Expand Up @@ -25,9 +27,7 @@ IQueryManager queryManager

[HttpPost, HttpGet]
[Route("{name}")]
public async Task<IActionResult> Query(
string name,
string parameters)
public async Task<IActionResult> Query(string name)
{
var query = await _queryManager.GetQueryAsync(name);

Expand All @@ -43,12 +43,30 @@ public async Task<IActionResult> Query(
return NotFound();
}

var queryParameters = parameters != null ?
string parameters;
if (Request.Method == "GET")
{
parameters = Request.Query["parameters"].ToString();
}
else if (Request.Method == "POST")
{
using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
{
parameters = await reader.ReadToEndAsync();
}
}
else
{
return BadRequest("Invalid request method");
}

var queryParameters = !string.IsNullOrEmpty(parameters) ?
JsonConvert.DeserializeObject<Dictionary<string, object>>(parameters)
: new Dictionary<string, object>();

var result = await _queryManager.ExecuteQueryAsync(query, queryParameters);
return new ObjectResult(result);
}

}
}

0 comments on commit 329ac70

Please sign in to comment.