in RESTProxy/Controllers/RootController.cs [44:121]
public async Task<HttpResponseMessage> RouteRequest(
string version,
string annotation,
string command = null,
string commandId = null,
string subCommand = null,
string subCommandId = null,
string subCommand2 = null,
string subCommandId2 = null,
string subCommand3 = null,
string subCommandId3 = null,
string subCommand4 = null,
string subCommandId4 = null,
string subCommand5 = null,
string subCommandId5 = null,
string subCommand6 = null,
string subCommandId6 = null,
string subCommand7 = null,
string subCommandId7 = null,
int skip = -1,
int top = -1)
{
// Grab the body (if it even exists)
string body = Encoding.UTF8.GetString(await Request.Content.ReadAsByteArrayAsync());
// Check to see if this should use the INT endpoint or stay with PROD.
// We don't care about the value of the header...just its existence.
IEnumerable<string> headerValues;
EndpointType endpointType = Request.Headers.TryGetValues("UseINT", out headerValues) ?
EndpointType.Int :
EndpointType.Prod;
// To support multi-tenant proxy servers, we need to check if the user provided a
// tenantId or tenantName as well.
string tenantId = null;
if (Request.Headers.TryGetValues("TenantId", out headerValues))
{
tenantId = headerValues.FirstOrDefault();
}
string tenantName = null;
if (Request.Headers.TryGetValues("TenantName", out headerValues))
{
tenantName = headerValues.FirstOrDefault();
}
// We must also extract out any relevant headers that a user may have set.
string correlationId = null;
if (Request.Headers.TryGetValues(ProxyManager.MSCorrelationIdHeader, out headerValues))
{
correlationId = headerValues.FirstOrDefault();
}
string clientRequestId = null;
if (Request.Headers.TryGetValues(ProxyManager.MSClientRequestIdHeader, out headerValues))
{
clientRequestId = headerValues.FirstOrDefault();
}
string clientName = null;
if (Request.Headers.TryGetValues(ProxyManager.ClientNameHeader, out headerValues))
{
clientName = headerValues.FirstOrDefault();
}
// Now, just proxy the request over to the real API.
return await ProxyManager.PerformRequestAsync(
pathAndQuery: Request.RequestUri.PathAndQuery,
method: Request.Method,
onBehalfOf: Request.GetRequestContext().Principal,
body: body,
tenantId: tenantId,
tenantName: tenantName,
endpointType: endpointType,
correlationId: correlationId,
clientRequestId: clientRequestId,
clientName: clientName);
}