Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetty 11 returns "/" as context path when deployed in ROOT context. It should return an empty string. #6028

Closed
tarator opened this issue Mar 3, 2021 · 7 comments
Labels
More Info Required Stale For auto-closed stale issues and pull requests Unable To Replicate

Comments

@tarator
Copy link

tarator commented Mar 3, 2021

Jetty version: 11.0.1

Java version: OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04)

OS type/version: Ubuntu Budgie 20.04.1

Description
When a WAR-File is deployed in ROOT Context Path of Jetty 11 the method getContextPath() returns the String / (slash).
It should return an empty String since context path's shouldn't end with a /

Jetty Versions <10 return an empty string as expected.

It seems this has also been a problem in Jetty 9, but has been fixed there: see #5057

@tarator tarator closed this as completed Mar 3, 2021
@tarator tarator reopened this Mar 3, 2021
@joakime joakime self-assigned this Mar 3, 2021
@joakime
Copy link
Contributor

joakime commented Mar 3, 2021

Seems that we have test cases for the .getContextPath() during DispatcherType.INCLUDE (which was added by issue #5057), but not normal REQUEST dispatch.

joakime added a commit that referenced this issue Mar 3, 2021
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
@joakime
Copy link
Contributor

joakime commented Mar 3, 2021

PR #6030 opened with testcase for Jetty 10 (it works there, but the OP says so anyway)

joakime added a commit that referenced this issue Mar 3, 2021
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
@joakime
Copy link
Contributor

joakime commented Mar 3, 2021

Opened PR #6032 for Jetty 11 with testcase.
This works as expected.

@janbartel
Copy link
Contributor

I can't replicate this with jetty-11.

Are you sure the request is not being wrapped?

joakime added a commit that referenced this issue Mar 3, 2021
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
@gregw
Copy link
Contributor

gregw commented Mar 3, 2021

I think there might be a difference ContextHandler.getContextPath() and ContextHandler.getServletContext().getContextPath()
I think the former will return what the context is configured as (eg "/" or "/foo"), but the later returns what the servlet spec wants (ie "" for root).

@joakime
Copy link
Contributor

joakime commented Mar 3, 2021

You can test this with the Dump servlet in the demo-jetty.war as well.

Setup ...

$ mkdir demo-base
$ cd demo-base
$ java -jar /opt/jetty-home-11.0.1/start.jar --add-module=http,deploy,demo-jetty
$ cd webapps
$ rm -rf demo-jetty.d demo-jetty.xml
$ mv demo-jetty.war ROOT.war
$ cd ..
$ java -jar /opt/jetty-home-11.0.1/start.jar

Then open http://localhost:8080/dump/info in your browser.
The getContextPath() returns an empty string.

joakime added a commit that referenced this issue Mar 10, 2021
…xtpath

Issue #6028 - Request.getContextPath() for root context should be empty string (Jetty 10)
@joakime joakime removed their assignment Nov 12, 2021
@github-actions
Copy link

This issue has been automatically marked as stale because it has been a
full year without activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@github-actions github-actions bot added the Stale For auto-closed stale issues and pull requests label Nov 13, 2022
@joakime joakime closed this as completed Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
More Info Required Stale For auto-closed stale issues and pull requests Unable To Replicate
Projects
None yet
Development

No branches or pull requests

4 participants