Performing a redirect based on URL and verb.

Not applicable

I'm trying to form a redirect to a specific endpoint -> /offers. I'm not exactly sure where to put the new header info in my flow. Here is the flow I added. It matches the verb and URL but, doesn't set the new header.

<Flow name="redirect-offers">
    <Response>
        <Set>
            <StatusCode>302</StatusCode>
            <Header name="Location">http://www.google.com</Header>
        </Set>
    </Response>
    <Condition>(proxy.pathsuffix MatchesPath "/offers") and (request.verb = "GET")</Condition>
</Flow>

Am I trying to set the header in the wrong place?

0 3 3,504
3 REPLIES 3

Hi Doug,

You will want to use an Assign Message policy to actually set the status code and header. You then add this Assign Message policy as a step in your flow.

Below is a sample Assign Message policy configuration

<AssignMessage name="Assign-Message-2">
    <Set>
        <Headers>
            <Header name="Location">https://www.google.com</Header>
        </Headers>
        <StatusCode>302</StatusCode>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

You would add that to your conditional flow something like this.

  <Flow name="redirect-offers">
    <Description/>
    <Request/>
    <Response>
      <Step>
        <Name>Assign-Message-2</Name>
      </Step>
    </Response>
    <Condition>(proxy.pathsuffix MatchesPath "/offers") and (request.verb = "GET")</Condition>
  </Flow>

I think that should do the trick.

yes, and you may need to "short-circuit" the target endpoint with a route rule. By that I mean, "tell Apigee to NOT route the request to the target for the endpoint, if the request will be 302-redirected." It would be something like this in your proxyendpoint:

  <RouteRule name="no-route">
    <Condition>(proxy.pathsuffix MatchesPath "/offers") and (request.verb = "GET")</Condition>
  </RouteRule>

...basically the same condition you are using in your Flow.

I was able to get it working. I had to modify my AssignMessage policy slightly and I put it in the flow. By creating flows early in the chain I did not require a RouteRule. Thanks for the help!

Final config...

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="RedirectOffers">
    <DisplayName>RedirectOffers</DisplayName>
    <Properties/>
    <Set>
        <StatusCode>302</StatusCode>
        <Headers>
            <Header name="Location">http://news.google.com</Header>
        </Headers>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>