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

UriComponentsBuilder should also contain subtractive methods [SPR-8803] #13445

Closed
spring-projects-issues opened this issue Oct 26, 2011 · 6 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 Oct 26, 2011

Kenneth DeLong opened SPR-8803 and commented

UriComponentsBuilder should have methods also to subtract and remove items from the URI. For example, I might want to take the current URL and remove the pagination parameter from the URL:

UriComponentsBuilder.parse(request).removeParameter("page").build();

Also, I might want to change the UriPath

UriComponentsBuilder.parse(request).removeParameter("page").setUriPath("/new/path").build();

The advantage of this is we might want to keep the incoming request's DNS name, port, scheme, etc. This is a portable way of constructing URLs across environments (dev/qa/staging/prod).

URLs are not always used for redirecting etc. I might need to send out an email with a link to some page on the site. I could use the above functionality to construct a URL with the correct port, scheme, etc. in a simple portable fashion.


Affects: 3.1 RC1

Issue Links:

Referenced from: commits 2a39f34, d3f4c69

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

Methods to replace the path and the query (or query params) have been added.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 7, 2011

Rossen Stoyanchev commented

A Servlet-variant of the UriComponentsBuilder will add options to create the UriComponentsBuilder from an HttpServletRequest. See #13465.

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

Kenneth, the ServletUriComponentsBuilder is now available and should match more closely the example you gave above.

@spring-projects-issues
Copy link
Collaborator Author

Kenneth DeLong commented

ServletUriComponentsBuilder looks nice.

I didn't see removeParameter(), I saw replace() but that will leave the parameter name in the query string. It's often useful to remove it completely.

Thanks!!

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

I've just updated replaceParameter(). If no values are provided, the parameter is removed.

@spring-projects-issues
Copy link
Collaborator Author

Kenneth DeLong commented

Looks great, thanks Rossen!

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