1

我目前正在使用 Krakend ( https://krakend.io ) API Gateway 将请求代理到我的后端服务。我的后端服务 API 响应之一是带有 http 303 的重定向响应。重定向响应如下所示:

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

问题是,Krakend 并没有按原样返回 http 303 响应给客户端(带有位置响应标头) ,而是遵循 http 重定向并返回重定向 Url 的响应,即https://的 html 响应www.detik.com/

我当前的 krakend 配置如下所示:

{
  "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
        }
      ]
    }
  ]
}

那么如何让 krakend 将原始的 http 303 响应从我的后端服务返回到客户端?

谢谢你

4

1 回答 1

1

我假设您正在调用此端点/ramatestredirect

要获取后端 http 状态码(如您所说,它返回 303 http 状态码),您可以使用以下方式:

{
  "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
    }
  ]
}

所以,基本上有了这个插件,你可以得到原始的后端 http 状态码

"github.com/devopsfaith/krakend/http": {
          "return_error_details": "authentication"
        }
于 2021-08-17T14:19:23.253 回答