virtualhost aliases always returns weird value

Hi @Dino-at-Google , @Anil Sagar @ Google

I am trying to fetch the value of apigee predefined variable i.e. virtualhost.aliases , this always gives back [Ljava.lang.String;@747f9a50.

Documents refers that is will return

virtualhost.aliases Array of Strings Read only Host aliases of the virtual host that is hit during a particular request. Proxy request
0 4 516
4 REPLIES 4

Yes, hmmmm...

That weird string is a Java language blob that indicates "this is an array of strings". And wow, the documentation is accurate, but the behavior when you fetch that variable is quite useless.

Unfortunately I don't know of a way, today, to allow the apiproxy to get the full array of strings representing vhost aliases in a usable form.

You can get virtualhost.name ... which gives you the current virtualhost name, but not the current vhost alias.

I can file a bug, but .. in order to prioritize it, Can you tell me why you want that information?

ref: b/128453178


Edit:

in the future, you will be able to retrieve virtualhost.aliases.values to get a JSON-stringified value of the list of aliases. It's a readonly variable. This is not in the current cloud release, but I expect it to be made available in the next cloud release.

Keep in mind, this is not the HOST header. It's the list of all the aliases on the vhost. ONE of them will be the same value as the host header.

Thanks @Dino-at-Google , for a quick response.

We want to have some custom logic in our proxy based on virtual host aliases (since we have a SAN cert)

I figured out a way of getting it done using different variable i.e. host header from request and kvm combination.

We don't need it urgently since we have a workaround in place. Just wanted to bring to your notice the issue we faced and wanted if we were only seeing the value of variable not getting returned correctly.

The Virtual Host is an array, so you need to use a javascript callout if you want the first value. This is what we used:

context.setVariable("vhalias", context.getVariable("virtualhost.aliases")[0])

There wasn't a way to extract the value with either:

    <Add>
        <Headers>
            <Header name="x-vhalias">{virtualhost.aliases[0]}</Header>
        </Headers>
    </Add>

Or

    <Add>
        <Headers>
            <Header name="x-vhalias">{virtualhost.aliases}[0]</Header>
        </Headers>
    </Add>

And upon further testing, the array of virtualhost.aliases is not much use as it is just an array of all the alias values you setup on the virtual host and I suspect need to query is the Host from the request. As that is the hostname being called rather than the hostnames configured.

So this is what you need.

<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables">
    <DisplayName>Extract Variables</DisplayName>
    <Properties/>
    <Header name="Host">
        <Pattern ignoreCase="false">{httphost}</Pattern>
    </Header>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <Source clearPayload="false">request</Source>
</ExtractVariables>