'How to configure Krakend so it return http redirect response as-is instead of following the http redirect?

I am currently using Krakend (https://krakend.io) API Gateway to proxy request to my backend service. One of my backend service API response is a redirect response with http 303. The redirect response looks like this below :

HTTP/1.1 303 See Other
content-length: 48
content-type: text/plain; charset=utf-8
date: Thu, 16 Jul 2020 10:25:41 GMT
location: https://www.detik.com/
vary: Accept
x-powered-by: Express
x-envoy-upstream-service-time: 17
server: istio-envoy

The problem is that, instead of returning the http 303 response to client (with location response header) as-is, Krakend is actually following the http redirect and return the response of the redirect Url, which is the html response of https://www.detik.com/.

My current krakend configuration looks like this below :

{
  "version": 2,
  "extra_config": {
    "github_com/devopsfaith/krakend-cors": {
      "allow_origins": [],
      "expose_headers": [
        "Content-Length",
        "Content-Type",
        "Location"
      ],
      "allow_headers": [
        "Content-Type",
        "Origin",
        "X-Requested-With",
        "Accept",
        "Authorization",
        "secret",
        "Host"
      ],
      "max_age": "12h",
      "allow_methods": [
        "GET",
        "POST",
        "PUT"
      ]
    },
    "github_com/devopsfaith/krakend-gologging": {
      "level": "ERROR",
      "prefix": "[GATEWAY]",
      "syslog": false,
      "stdout": true,
      "format": "default"
    },
    "github_com/devopsfaith/krakend-logstash": {
      "enabled": false
    }
  },
  "timeout": "10000ms",
  "cache_ttl": "300s",
  "output_encoding": "json",
  "name": "api-gateway",
  "port": 8080,
  "endpoints": [
    {
      "endpoint": "/ramatestredirect",
      "method": "GET",
      "extra_config": {},
      "output_encoding": "no-op",
      "concurrent_calls": 1,
      "backend": [
        {
          "url_pattern": "/",
          "encoding": "no-op",
          "sd": "static",
          "extra_config": {},
          "method": "GET",
          "host": [
            "http://ramatestredirect.default.svc.cluster.local"
          ],
          "disable_host_sanitize": false
        }
      ]
    }
  ]
}

So how can I make krakend to return original http 303 response unaltered from my backend service to the client ?

Thank You



Solution 1:[1]

I assume that you're calling this endpoint /ramatestredirect

To get backend http status code (as you said it return 303 http status code), you can use this way:

{
  "endpoint": "/ramatestredirect",
  "method": "GET",
  "extra_config": {},
  "output_encoding": "no-op",
  "concurrent_calls": 1,
  "backend": [
    {
      "url_pattern": "/",
      "encoding": "no-op",
      "sd": "static",
      "extra_config": {
        "github.com/devopsfaith/krakend/http": {
          "return_error_details": "authentication"
        }
      },
      "method": "GET",
      "host": [
        "http://ramatestredirect.default.svc.cluster.local"
      ],
      "disable_host_sanitize": false
    }
  ]
}

So, basically with this plugin you can get the original backend http status code

"github.com/devopsfaith/krakend/http": {
          "return_error_details": "authentication"
        }

Solution 2:[2]

If you use Lura Framework (formerly known as Kraken framework), then you may have to disable redirects for your http client.

client := &http.Client{
    CheckRedirect: func(req *http.Request, via []*http.Request) error {
        return http.ErrUseLastResponse
    },
}

Solution 3:[3]

Assuming he could move diagonally the answer is:

def _dist(x1, y1, x2, y2):
    return max(abs(x1 - x2),abs(y1 - y2))

That's because he would do diagonally as many steps as there are units on the shortest axis plus as many steps as the difference in length between the axes: min + max - min = max

Solution 4:[4]

The answer is simple use math function, it will take O(1):

def _dist(x1, y1, x2, y2):
    return max(abs(x1 - x2),abs(y1 - y2))

Solution 5:[5]

You could do like this:

def _dist(x1, y1, x2, y2):
    return max(abs(x1-x2), abs(y1-y2))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 irnugr
Solution 2 Igor Lazarev
Solution 3 EllipticBike38
Solution 4
Solution 5 Paul Kocian