ServiceStack Proxy returns 200 but doesn't hit server

24 Views Asked by At

I have plugged in 2 instances of ProxyFeature because I have APIs that calculate the bearer token differently. One instance works fine, but the other always returns a 200 and an empty response body. I'm using Postman to query my ServiceStack API for testing.

Not Working

Plugins.Add(new ProxyFeature(
    r => r.PathInfo.StartsWith("/identity"),
    r => $"{services.IdentityServer.HostUrl}{r.RawUrl.Replace("/identity", "")}")
{
    ProxyRequestFilter = async (req, downstreamRequest) =>
    {
        // Customize the HTTP Request Headers that are sent to downstream server
        var myToken = MyLogicForTheTokenToUse();

        downstreamRequest.AddBearerToken(myToken);

        logger.DebugFormat("serialize: {request}", JsonSerializer.Serialize(downstreamRequest));
        logger.DebugFormat("Authorization: {Authorization}", downstreamRequest.Headers["Authorization"]);
    }
});

The log statements show me a good request. It looks good enough for me to manually execute them. The authorization header is "Bearer MyTokenValue". The URL is the correct value too.

Am I misinterpreting the info? What am I missing?

I have inspected the body in TransformRequest. I see the body from my original request. So that is good.

I have not seen my loggers hit in TransformResponse or ProxyResponseFilter. I'm not sure how to interrupt all of this.

Interruptions?

  1. My request made it to the downstream server, but it failed on that server and somehow Proxy didn't didn't tell me (Unlikely)
  2. My request didn't leave my server because I screwed up somewhere (strong theory)

I'm leaning towards No 2, because the destination server is not logging any incoming requests. I know it CAN long them because I exercise it directly and see its logs.

How else do I troubleshoot this Proxy feature?

For reference, here is my proxy feature that works

Plugins.Add(new ProxyFeature(
    r => r.PathInfo.StartsWith("/benefits"),
    r => $"{services.BenefitsApi.HostUrl}{r.RawUrl.Replace("/benefits", "")}")
{
    ProxyRequestFilter = async (req, downstreamRequest) =>
    {
        // Customize the HTTP Request Headers that are sent to downstream server
        logger.DebugFormat("event: {event}", "ProxyRequestFilter");

        var myToken = MyLogicForTheTokenToUse();
        var jsonApiClient = new JsonApiClient(services.BenefitsApi.HostUrl);
        var authenticationResponse = jsonApiClient.ApiAsync(new Authenticate()
        {
            provider = Constants.Authentication.BearerProviderName,
            oauth_token = myToken.Result
        });

        if (authenticationResponse.IsFaulted)
        {
            logger.ErrorFormat("Failed to authenticate with downstream service {downstreamUri}: {errorMessage}", services.BenefitsApi.HostUrl, authenticationResponse.Result.ErrorMessage);
        }

        downstreamRequest.AddBearerToken(authenticationResponse.Result.Response?.BearerToken);
    }
});
0

There are 0 best solutions below