Open vickyRathee opened 2 years ago
That should work just fine. Does it not work?
No, it doesn't work. I tried to specify Task<Task>
on return type, as Task.FromResult return a task with type T. So I need some way to return any type
public async Task<Task> method(){
....
}
VS Console - I see 200 status on debug console
info: System.Net.Http.HttpClient.AspNetCore.Proxy.HttpProxyClient.ClientHandler[101]
Received HTTP response headers after 11.377ms - 200
info: System.Net.Http.HttpClient.AspNetCore.Proxy.HttpProxyClient.LogicalHandler[101]
End processing HTTP request after 15.7907ms - 200
API - but no data in API response. It says 204 status code
Can you try?
public async void StopJob(long id)
{
var job= await _jobService.getJobAsync(id);
if (job == null)
{
return Task.FromResult(Logger.Error($"No worker found"));
}
string workerUrl = $"{job.worker_url}/jobs/{id}/stop";
return await this.HttpProxyAsync(workerUrl);
}
No that causes build errors - CS0127 Controller returns void, a return keyword must no be followed by an object expression.
It only work when Task
type is returned. I tried with public async Task<Task>
as well, but it return 204 status from proxied API with no content
Sorry, I meant this.
public async void StopJob(long id)
{
var job= await _jobService.getJobAsync(id);
if (job == null)
{
return Task.FromResult(Logger.Error($"No worker found"));
}
string workerUrl = $"{job.worker_url}/jobs/{id}/stop";
await this.HttpProxyAsync(workerUrl);
}
That throws ObjectDisposed
exception -
Ok, I will need to try to repro.
Any chance you could add a test that repros your issue?
the only way I found is to have two downstream APIs and by condition direct the traffic to one of them
[HttpPost]
[Route("orders")]
public Task GetOrders()
{
var newServiceEnabled = getNewServiceEnabledAsync().Result;
if (newServiceEnabled)
{
return this.HttpProxyAsync("https://new-service.com/orders", _proxyOptions);
}
return this.HttpProxyAsync("https://old-service.com/orders", _proxyOptions);
}
I want to check some conditions on DB, before making a redirect to proxy. Any suggestion on code below.
All, I need is get the worker URL from database using
getJobAsync()
function before making a request to proxy..Because there may be 100s of running workers and I need to use the specific worker URL to proxy from the API.