feat(ProxyController): Cookies und Header hinzugefügt

This commit is contained in:
Developer 02 2025-01-30 13:34:04 +01:00
parent 61bb5acdff
commit 3eed85e7de
2 changed files with 19 additions and 5 deletions

View File

@ -16,13 +16,27 @@ public class ProxyController(IOptions<OriginServerParams> originServerParamsOpti
[HttpPost("{servicetierName}/ODataV4/{webserviceName}_CreateInvoice")]
public async Task<IActionResult> Redir([FromRoute] string servicetierName, [FromRoute] string webserviceName, [FromQuery] string company)
{
var res = await _origin.Url
var req = _origin.Url
.AppendPathSegment(servicetierName)
.AppendPathSegment("ODataV4")
.AppendPathSegment(webserviceName + "_CreateInvoice")
.SetQueryParams(new { company })
//.WithOAuthBearerToken("my_oauth_token")
.PostAsync();
.WithHeader("X-Forwarded-For", _origin.Url);
// Add default headers
foreach (var header in _origin.DefaultHeaders)
req = req.WithHeader(header.Key, header.Value);
// Add request headers
foreach (var header in HttpContext.Request.Headers)
req = req.WithHeader(header.Key, header.Value);
// Add reqest cookies
foreach (var cookie in HttpContext.Request.Cookies)
req = req.WithCookie(cookie.Key, cookie.Value);
//post request
var res = await req.PostAsync();
//merge with default headers
var mergedDictionary = _origin.DefaultHeaders

View File

@ -9,7 +9,7 @@
"OriginServer": {
"Url": "https://localhost:7248",
"DefaultHeaders": {
"foo": "bar"
"Authorization": "Basic eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
}
}
}
}