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

@RequestMapping matching should be insensitive to trailing slashes [SPR-5636] #10307

Closed
spring-projects-issues opened this issue Mar 30, 2009 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 30, 2009

Grzegorz Borkowski opened SPR-5636 and commented

For full discussion, see my article: http://grzegorzborkowski.blogspot.com/2009/03/test-drive-of-spring-30-m2-rest-support.html

Some citations from it:

"For RESTful web services (...) URLs actually represent virtual directories. This means that common rule "trailing slash doesn't matter" (especially for URL representing "list of resources") should be respected: http://mydomain/restservice/v1/projects address is equivalent to http://mydomain/restservice/v1/projects/ address. If you consider that each project is also the container for its tasks or assignments, then also http://mydomain/restservice/v1/projects/MyProject should be equivalent to http://mydomain/restservice/v1/projects/MyProject/, etc."

@PathMapping annotation is broken when it comes to handling those trailing slashes:

"If I mark controller class with @RequestMapping("/projects") then only request without trailing slash will be matched. If trailing slash is appended to the actual request, we get 404 response. What's worse, method-level annotation will not be appended to base URL in this case. So we have to change it to @RequestMapping("/projects/*"). Now methods will work, but if you send request to base url to get list of projects, and forget the slash at the end, you will get 404 response again. That's very bad in my opinion. JAX-RS handles it properly: see JAX-RS's @Path Javadoc."

For reference: https://jsr311.dev.java.net/nonav/releases/1.0/javax/ws/rs/Path.html

This issue is related also to #10302.


Affects: 3.0 M3

Issue Links:

Referenced from: commits c225b44

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Fixed.

@spring-projects-issues
Copy link
Collaborator Author

Grzegorz Borkowski commented

(Looks like Spring's Jira has some problems recently, as my comment ended up with server error "Issue doesn't exits any longer". Strange. Let's try again, then.)

I've encountered problem related to this issue. I have REST controller with methods mapped to URL of that form:
http://host/restservice/organizations/{domainName}

If I send request to http://host/restservice/organizations/example.com/ (with trailing slash) it is mapped properly.
If I send it without trailing slash, I get 404.

I assume this is because URL ending with *.* (containing dot character) are treated in special way, as virtual files, not virtual directories. I thought escaping . will help: http://host/restservice/organizations/example%2Ecom - but it doesn't, still 404.

Now I wonder if this is correct behavior. The case is obviously a bit uncommon, but... Perhaps special treatment of paths containing dot character is not needed at all? Do we really need it for any purpose?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants