Zuul返回HTTP状态200而不是302

问题描述 投票:2回答:2

我有一个叫做Backend(端口:9090)的服务,坐在Zuul后面(端口:8080)。

浏览器在Zuul上调用GET方法,该方法进行重定向。

示例调用:http://localhost:8080/testredirect

结果:

预期结果:

  • 浏览器应该接收Http status = 302并更改URL,从而导致:
  • 浏览器网址:http://localhost:8080/hello
  • 浏览器显示:“Hello world”

似乎Zuul返回200,因为它的代理服务器隐藏了重定向。

当在服务器端的GET方法中定义URL时,如何在浏览器中实现302重定向?

这是后端服务:

@SpringBootApplication
public class BackendApplication {

    @RestController
    @RequestMapping
    public class Backend {
        @GetMapping(value = "/hello")
        public String sayHello() {
            return "Hello world";
        }

        @GetMapping(value = "/testredirect")
        public RedirectView sayRandom() {
            return new RedirectView("/hello");
        }

       public static void main(String[] args) {
          SpringApplication.run(BackendApplication.class, args);
       }
    }
}

以下是Zuul的配置:

server:
  port: 8080
zuul:
  routes:
    core:
      sensitive-headers:
      path: /core/**
      url: http://localhost:9090/

注意:spring cloud - > Edgware.RELEASE

spring-cloud netflix-zuul
2个回答
0
投票

Spring-boot发行版Edgeware.RELEASE中的功能已更改。

在Edgeware.RELEASE中:返回200,以及页面的内容。

在Dalston.SR4中:返回302并且浏览器重定向。


0
投票

您可以在Spring上下文中定义bean。

@Bean 
public ApacheHttpClientFactory apacheHttpClientFactory() {
     return new ApacheHttpClientFactory() {
         @Override 
         public HttpClientBuilder createBuilder() {
             return HttpClientBuilder.create()
                     .disableContentCompression()
                     .disableCookieManagement()
                     .useSystemProperties()
                     .disableRedirectHandling();
         }
     }
 }
© www.soinside.com 2019 - 2024. All rights reserved.