sumisu3
sumisu3

Reputation: 31

Apigee proxy SSL CLASSIFICATION_FAILURE 404 vs. 301 REDIRECT

When I have an API that only accepts HTTPS and I make an HTTP request the default seems to be a 404 error. Is there a way to automatically redirect to the HTTPS URL?

Upvotes: 1

Views: 936

Answers (2)

Srikanth
Srikanth

Reputation: 1025

I would go with similar approach described here of catch all and redirect. Catch all proxy always redirects. You need not raise a fault, you can do it in response flow of catch all proxy.

Upvotes: 0

carloseberhardt
carloseberhardt

Reputation: 93

One easy way to do this is with a conditional RaiseFault policy.

Here's a simple example of

The RaiseFault policy looks as follows:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RaiseFault async="false" continueOnError="false" enabled="true" name="301tossl">
<DisplayName>301toSSL</DisplayName>
<FaultRules/>
<Properties/>
<FaultResponse>
    <Set>
        <Headers>
          <Header name="Location">https://{request.header.host}{request.uri}</Header>
      </Headers>
        <Payload contentType="text/plain">SSL Required.
        </Payload>
        <StatusCode>301</StatusCode>
        <ReasonPhrase>Moved Permanently</ReasonPhrase>
    </Set>
</FaultResponse>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>

And the here's an example of putting a condition on the policy (in the preflow in this case):

<PreFlow name="PreFlow">
    <Request>
        <Step>
            <FaultRules/>
            <Name>301tossl</Name>
            <Condition>client.scheme = "http"</Condition>
        </Step>
    </Request>
    <Response/>
</PreFlow>

I've got a sample here if you want to download -> https://github.com/carloseberhardt/edge-samples/tree/master/proxies/301ssl

Upvotes: 1

Related Questions