feat(ProxyController): Optionaler Körper als Dictionary<string, object> hinzugefügt

This commit is contained in:
Developer 02 2025-01-30 15:11:38 +01:00
parent 54fce2990b
commit 6dc8bd233b
2 changed files with 7 additions and 7 deletions

View File

@ -6,7 +6,7 @@ namespace DigitalData.Swagger.MockAPI.Controllers
public class MockController : ControllerBase
{
[HttpPost("{servicetierName}/ODataV4/{webserviceName}_CreateInvoice")]
public IActionResult CreateInvoice([FromRoute] string servicetierName, [FromRoute] string webserviceName, [FromQuery] string company)
public IActionResult CreateInvoice([FromRoute] string servicetierName, [FromRoute] string webserviceName, [FromQuery] string company, Dictionary<string, object>? body)
{
return Created($"{servicetierName}/ODataV4/{webserviceName}?id={1}", new { Id = 1, Foo = 1});
}

View File

@ -14,7 +14,7 @@ public class ProxyController(IOptions<OriginServerParams> originServerParamsOpti
private readonly OriginServerParams _origin = originServerParamsOptions.Value;
[HttpPost("{servicetierName}/ODataV4/{webserviceName}_CreateInvoice")]
public async Task<IActionResult> Redir([FromRoute] string servicetierName, [FromRoute] string webserviceName, [FromQuery] string company)
public async Task<IActionResult> Redir([FromRoute] string servicetierName, [FromRoute] string webserviceName, [FromQuery] string company, [FromBody] Dictionary<string, object>? body = null)
{
var req = _origin.Url
.AppendPathSegment(servicetierName)
@ -22,7 +22,7 @@ public class ProxyController(IOptions<OriginServerParams> originServerParamsOpti
.AppendPathSegment(webserviceName + "_CreateInvoice")
.SetQueryParams(new { company })
.WithHeader("X-Forwarded-For", HttpContext.Connection.RemoteIpAddress?.ToString());
// Add default headers
foreach (var header in _origin.DefaultHeaders)
req = req.WithHeader(header.Key, header.Value);
@ -36,7 +36,7 @@ public class ProxyController(IOptions<OriginServerParams> originServerParamsOpti
req = req.WithCookie(cookie.Key, cookie.Value);
//post request
var res = await req.PostAsync();
var res = body is null ? await req.PostAsync() : await req.PostJsonAsync(body);
// set headers
foreach (var (Name, Value) in res.Headers)
@ -46,10 +46,10 @@ public class ProxyController(IOptions<OriginServerParams> originServerParamsOpti
foreach (var (Name, Value) in res.Cookies.ToKeyValuePairs())
HttpContext.Response.Cookies.Append(Name, Value.ToString() ?? string.Empty);
var body = res.GetJsonAsync<dynamic>();
var resBody = res.GetJsonAsync<dynamic>();
if (body is not null)
return new JsonResult(body)
if (resBody is not null)
return new JsonResult(resBody)
{
StatusCode = res.StatusCode
};