spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Add default filters to routes create by route DSL

Open yangdd1205 opened this issue 6 years ago • 8 comments

Hi

I define a route using API don't support for default filter.

this is my code

@Bean
public RouteLocator hiServerRouteLocator(RouteLocatorBuilder builder) {
    return builder.routes()
            .route("hi-server", r -> r.path("/hi-server/**")
                    .filters(f -> f.rewritePath("/hi-server/(?<remaining>.*)", "/${remaining}")
                    ).uri("lb://hi"))
            .build();
}

define a default filter in configure file

spring:
  application:
    name: gateway
  cloud:
    gateway:
      default-filters: 
      - name: AddResponseHeader
        args:
          name: X-Response-Default-Foo
          value: Default-Bar

access the url http://localhost:9999/hi/hi

HTTP/1.1 200 OK
Content-Length: 3
Content-Type: text/plain;charset=UTF-8
Date: Mon, 02 Apr 2018 02:11:13 GMT
X-Response-Default-Foo: Default-Bar  # default filter is work

hi!

access the url http://localhost:9999/hi-server/hi

HTTP/1.1 200 OK
Content-Length: 3
Content-Type: text/plain;charset=UTF-8
Date: Mon, 02 Apr 2018 02:12:39 GMT

# default filter don't work

hi!

Java routes API don't support for default filters or how to do it ?

The spring cloud gateway version is 2.0.0.M9

yangdd1205 avatar Apr 02 '18 03:04 yangdd1205

Would be really useful bit blocked from using gateway as I can't use yaml config because I need or() & alwaysTrue and can't use java config because I need default filters.

RobMaskell avatar May 19 '18 14:05 RobMaskell

I'm currently declaring routes with with RouterFunctions.route() passing a HandlerFunction that make calls to different microservices. Having the ability to use default filters via configuration would unlock many cloud gateway functionalities in this case. :)

echoesbr avatar Dec 03 '19 13:12 echoesbr

Not sure how that relates add that comes from webflux and gateway filters don't apply there

spencergibb avatar Dec 03 '19 14:12 spencergibb

Got same problem when use 2.2.0.RELEASE. Is it solved?

jiangchang-start avatar Jun 18 '20 07:06 jiangchang-start

Any updates?

wuxudong avatar Jun 11 '22 14:06 wuxudong

Would this be fixed soon? I am also facing issue...

rremanan-bwi avatar Sep 21 '22 16:09 rremanan-bwi

This would be nice to have fixed. We have a bunch of routes that configure CORS and come back with duplicate response headers so each java DSL route has to have that DedupeResponseHeader filter

austinmehmet avatar Mar 26 '24 21:03 austinmehmet