spring-cloud / spring-cloud/spring-cloud-gateway

Add default filters to routes create by route DSL

Open
#263 9 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #2124 by @ctlove0523 — closed without merging
enhancement
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the Java RouteLocatorBuilder example and the YAML default-filters configuration in the issue, then inspect closed pull request #2124 for prior work. Reproduce the contrasting requests to /hi/hi and /hi-server/hi and verify whether the configured response header is applied to routes created through the DSL.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.