Arjen Poutsma opened SPR-15953 and commented

We could use a WebFluxUriComponentsBuilder that has similar functionality as the ServletUriComponentsBuilder,

An additional method that WebFluxUriComponentsBuilder should have is fromServerRequest, taking a ServerRequest from WebFlux.fn, as that type does not implement HttpRequest, and therefore cannot be used with UriComponentsBuilder.fromHttpRequest.


Issue Links: - #20485 ReactorServerHttpRequest.getUri() does not include scheme - #20546 WebFlux support for UriBuilder, UriComponentsBuilder controller method arguments

Referenced from: commits https://github.com/spring-projects/spring-framework/commit/1a3cc3df94c0f8e504f36e9be8e6f2ded5a12750, https://github.com/spring-projects/spring-framework/commit/a7617a264120ca486d7c92bb4255ec1ac3ef986e

Comment From: spring-projects-issues

Rossen Stoyanchev commented

ServerRequestUriComponentsBuilder has methods to build from a request instance. Considering that UriComponentsBuilder.fromHttpRequest already exists what else would WebFluxUriComponentsBuilder have besides a fromServerRequest(ServerRequest) method?

Note that we will also need an equivalent of MvcUriComponentsBuilder where the name WebFluxUriComponentsBuilder would be a good fit.

Comment From: spring-projects-issues

Rossen Stoyanchev commented

An alternative idea is something like ServerRequest.relativeToRequestUri returning UriComponentsBuilder.

Comment From: spring-projects-issues

Arjen Poutsma commented

Initial version committed at https://github.com/spring-projects/spring-framework/commit/a7617a264120ca486d7c92bb4255ec1ac3ef986e.

As discussed, Rossen Stoyanchev will add subsequent @Controller-related methods.

Comment From: spring-projects-issues

Rossen Stoyanchev commented

Arjen Poutsma taking a quick look, for WebFluxUriComponentsBuilder to have @Controller methods its current location could be an issue. MvcUriComponentsBuilder by comparison in is in the same package as all the other annotation related classes. Even if we don't run into circular dependencies, arguably such a builder should be in the annotations package. Also I can't imagine that using such a WebFluxUriComponentsBuilder from the functional framework -- with a ton of @Controller methods and only 1 for ServerRequest, is ideal.

Since what is needed for ServerRequest is a trivial one-liner, could we find another solution perhaps? ServerRequest has a uri() method. What about a uriComponentsBuilder next to it?

Comment From: spring-projects-issues

Arjen Poutsma commented

??Since what is needed for ServerRequest is a trivial one-liner, could we find another solution perhaps? ServerRequest has a uri() method. What about a uriComponentsBuilder next to it???

That sounds like a good idea. I will move the method from WebFluxUriComponentsBuilder to ServerRequest, and remove WebFluxUriComponentsBuilder altogether.

Comment From: spring-projects-issues

Arjen Poutsma commented

Done, see https://github.com/spring-projects/spring-framework/commit/1a3cc3df94c0f8e504f36e9be8e6f2ded5a12750

Comment From: spring-projects-issues

Rossen Stoyanchev commented

Now that ServerRequest has an option and #20546 adds the same controllers methods, this is less critical for 5.0 GA. I'm postponing for 5.1.

Comment From: poutsma

Closing, as I don't think we need this anymore.

Comment From: gregturn

Spring HATEOAS, which is currently coding reactor support, could use it.

Comment From: treuherz

Without this functionality, is there any way to generate URIs based on controller methods? From @poutsma's comment I assumed the functionality of MvcUriComponentsBuilder would be replicated by the additions that were made in bdde0f1 and 1a3cc3d, but it doesn't seem that way. If a UriComponentsBuilder is injected as an argument to a handler method, there is still no reliable way to construct a link with that to another method on a controller, the way MvcUriComponentsBuilder#fromMethod does.