Open spring-projects-issues opened 7 years ago
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.
Rossen Stoyanchev commented
An alternative idea is something like ServerRequest.relativeToRequestUri
returning UriComponentsBuilder
.
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.
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?
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.
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.
Closing, as I don't think we need this anymore.
Spring HATEOAS, which is currently coding reactor support, could use it.
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.
Arjen Poutsma opened SPR-15953 and commented
We could use a
WebFluxUriComponentsBuilder
that has similar functionality as theServletUriComponentsBuilder
,An additional method that
WebFluxUriComponentsBuilder
should have isfromServerRequest
, taking aServerRequest
from WebFlux.fn, as that type does not implementHttpRequest
, and therefore cannot be used withUriComponentsBuilder.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