Skip to content

Routing broken in 4.2.1 with stripPrefix filter and others #3736

@thomas-seag

Description

@thomas-seag

Describe the bug
In Spring Cloud Gateway MVC 4.2.1 (included via spring-cloud-dependencies 2024.0.1) routing is broken with the StripPrefix filter.

The original URI comes in to the gateway as http://localhost:8080/foo/bar/baz. Route config:

server:
  port: 8000

spring:
  cloud:
    gateway:
      mvc:
        routes:
          - id: bar
            uri: http://localhost:9000
            predicates:
              - Path=/foo/bar/**
            filters:
              - DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
              - TokenRelay=
              - StripPrefix=2

Final URL to forward to should be http://localhost:9000/baz.

This works with Gateway MVC 4.2.0. It fails with 4.2.1, which tries to connect to http://localhost:8080/baz.

Analysis

This is a recurrence of #3055 and #3178, only this time for all the functions in which commits b8200a3 and b82da55 added these MvcUtils.setRequestUrl() calls. For instance in stripPrefix at

This overwrites the configured route URI, and in the end the forward goes to the wrong server.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions