问题
Our Apigee configuration looks a little like this:
Netscaler LB -> Apigee Router/Message Processor -> Netscaler LB - Target Server(s)
The target server in this case is a Java appliation with Jersey, and I'm using the Jersey @Context to retrieve the relevant URI info to set for example Location headers, but all the request details seem to relate to the Netscaler and not the originating request.
If we use an AssignMessage policy and manually set the X-Forwarded-Host URL to be the URL the client calls then everything works as it should do. Unfortunately there doesn't seem to be a variable we can use instead of hardcoding this - everything in the docs around the variables seems to indicate you can only get the paths after the domain itself.
回答1:
While in the <ProxyEnpoint>
request segment, you can reference the variable request.header.host
and it will give you the host that the client requested into Apigee.
For example, if you URI is https://myorg-test.apigee.net/resource, request.header.host
in the request segment of the ProxyEndpoint will have a value of myorg-test.apigee.net
.
If you try to reference this in the TargetEndpoint
, it may already be overwritten to with the backend host for the target request. If you need it in the TargetEndpoint, assign it to a variable first in the ProxyEndpoint/PreFlow/Request
and you can later reference the variable originalHost
:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="grabOriginalHost">
<AssignVariable>
<Name>originalHost</Name>
<Ref>request.header.host</Ref>
</AssignVariable>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>
来源:https://stackoverflow.com/questions/24572542/how-do-you-correctly-return-location-headers-and-do-hateoas-with-apigee