J Freebird
J Freebird

Reputation: 3910

Zuul Rewrites Host Name after Routing

Whenever a request hits Zuul, I got a 302 redirect to the host of the actual service to be called. So the url gets rewritten by Zuul. I want to prevent this. The user should only see the hostname of Zuul.

I have a Spring Cloud Zuul that I use as a routing server. It has the following configs:

zuul:
  ignoredServices: '*'
  routes:
    service1:
      path: /service1/**
      serviceId: service1
      stripPrefix: false
    service2:
      path: /service2/**
      serviceId: service2
      stripPrefix: false
    login:
      path: /login/**
      sensitiveHeaders:
      serviceId: login
      stripPrefix: false

And Zuul is using Eureka for the service discovering. Suppose logingateway is running on localhost:8081 and Zuul on localhost:8080. If go to localhost:8080/login, I'll get a 302 first and then to localhost:8081/login. I don't want 302 redirect and I want the hostname to stay the same. I didn't find any related document on this issue. Thanks.

Upvotes: 2

Views: 2463

Answers (1)

Shawn Clark
Shawn Clark

Reputation: 3440

As @spencergibb commented Zuul doesn't do any rewrite of the HTTP response. There is an open issue around this as well: https://github.com/spring-cloud/spring-cloud-netflix/issues/8. The consensus is that Zuul won't provide that but the scope got narrowed to just rewriting the location header which is part of the 302 redirect response. You can follow that issue to see where it goes but as it stands right now that isn't possible with Zuul built-in filters.

You can always create your own Post filter for Zuul to do this yourself. Check out the Zuul documentation to understand when filters are executed: https://github.com/Netflix/zuul/wiki/How-it-Works then read on how to write your own filter: https://github.com/Netflix/zuul/wiki/Writing-Filters

Upvotes: 2

Related Questions