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

spring-cloud-gateway MVC incorrectly includes the contextPath when calling downstream servers

Open
#3,866 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feedback-provided
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

Describe the bug
When server.servlet.contextPath is set, the url used to forward the request includes the contextPath e.g.
with server.servlet.contextPath: gateway. On receipt of /gateway/some/path the request path sent to the downstream server is /gateway/some/path which is not correct and should be /some/path.

It seems to me that the issue here is that serverRequest.requestPath() is used when in fact serverRequest.requestPath().pathWithinApplication() should be used. This is also the case in the filters e.g. stripPrefix(1) will result in /some/path (contextPath is stripped) being sent when it should be /path.

version: 4.1.9

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 tracing uses of serverRequest.requestPath() in the Spring Cloud Gateway MVC forwarding path and related filters. Compare requestPath() with requestPath().pathWithinApplication() for a configured server.servlet.contextPath, including stripPrefix(1). Done means downstream requests exclude the context path while prefix stripping still removes the expected additional segment.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.