apigeeapigee-baas

Apigee Proxy passing same host header to target


I have a simple apigee proxy, but I can see in the trace an issue where the Host header going to the target contains the host of the proxy itself.

i.e. the target gets

Host: xx.apigeename.com

rather than:

Host: my.awsservername.com

The target is on a different domain to the proxy, so it means that the target server is improperly handling the request (404 in this case).

Why is it that Apigee might be sending the exact same host header and not transforming it?

I have tried to explicitly set it, by setting the TargetEndpoint:

<TargetEndpoint name="xyzzy">
    <Description/>
    <FaultRules/>
    <PreFlow name="PreFlow">
        <Request>
            <Headers>
                <Header name="Host">{target.host}</Header>
            </Headers>
        </Request>
        <Response>
        </Response>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows/>
    <HTTPTargetConnection>
        <Properties/>
        <URL>https://{targetBackend}/xyzzy</URL>
        <SSLInfo>
            <Enabled>true</Enabled>
            <Protocols>
                <Protocol>TLSv1.2</Protocol>
            </Protocols>
        </SSLInfo>
    </HTTPTargetConnection>
</TargetEndpoint>

The documentation Apigee has on this seems very vague.

It's getting super frustrating. We have other proxies that are working fine without doing anything special.


Solution

  • This seems odd. Apigee should not do that by default. Are you sure that other flows are setup correctly? Anyhow.. you can try to create a AssignMessage policy that adds the correct host. Take a look at this: https://docs.apigee.com/api-platform/reference/policies/assign-message-policy#Samples

    ./policies/hostPolicy.xml:

    <AssignMessage name="hostPolicy" continueOnError="false">
      <AssignTo createNew="false" type="request"></AssignTo>
      <Set>
        <Headers>
         <Header name="Host">{target.host}</Header>
        </Headers>
      </Set>
    </AssignMessage>
    

    ./targets/xyzzy.xml

      <PreFlow name="PreFlow">
        <Request>
          <Step>
            <Name>hostPolicy</Name>
          </Step>
        </Request>
      </PreFlow>
    

    NB: I haven't tested this. Read the vague apigee docs on policies