Skip to content

UriComponentsBuilder should provide a way to remove the extension from the path [SPR-10272] #14906

@spring-projects-issues

Description

@spring-projects-issues

Daniel Gredler opened SPR-10272 and commented

Spring supports using both "Accept" HTTP headers and extensions (e.g. .xml and .json) for content type negotiation. However, if the client uses extensions, any URLs built using the UriComponentsBuilder will contain the extension.

For example, if the client GETs this book:

http://foo.com/rest/books/6

and you want the server to return a list of the URLs for each of the pages in the book, e.g.

http://foo.com/rest/books/6/pages/1

then if the client is using extensions for content type negotiation you end up with the following URI:

http://foo.com/rest/books/6.json/pages/1

if you use the standard URI building code:

fromCurrentRequest().path("/pages/{id}").buildAndExpand(pageId).toString()

It should be possible to remove the extension if it's there (or just ignore the removal if there is no extension):

fromCurrentRequest().removeExtension().path("/pages/{id}").buildAndExpand(pageId).toString()

Affects: 3.2 GA

Referenced from: commits 5017855

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions