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

Provide the HttpRequest on the ClientResponse interface #28397

Closed
jonathannaguin opened this issue Apr 29, 2022 · 1 comment
Closed

Provide the HttpRequest on the ClientResponse interface #28397

jonathannaguin opened this issue Apr 29, 2022 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@jonathannaguin
Copy link

The ClientResponse currenly does not provide an accessor to the HttpRequest object for which it was built.

This could be useful on (ExchangeFilterFunction)(https://github.com/spring-projects/spring-framework/blob/main/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunction.java) when handling redirects that happen at the TcpClient level.

Take for example the following sample:

    public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next)
    {
        return next.exchange(request)
                   .doOnSubscribe(s -> {
                       logger.info("--> " + request.method() + ' ' + request.url()); //1
                   })
                   .doOnError(error -> logger.info("<-- HTTP FAILED", error))
                   .timed()
                   .map(timed -> {
                       var tookMs = timed.elapsed().toMillis();
                       var response = timed.get(); //2
                       logger.info("<-- {} {}", response.statusCode(), request.url());
                       return response;
                   });
    }

In the line "1", I print the URL being requested originally, however the URL that it was finally used could be different on "2" if a redirect was followed. At the moment, there isn't a way of accessing that information from the ClientResponse object.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 29, 2022
@rstoyanchev rstoyanchev added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jan 24, 2023
@rstoyanchev
Copy link
Contributor

I don't see why we couldn't do that, and there is already a method on ClientResponse#Builder to set the request. Having the corresponding accessor to then expose it from the created ClientResponse makes sense.

@rstoyanchev rstoyanchev added this to the 6.1.0-RC1 milestone Oct 2, 2023
@rstoyanchev rstoyanchev added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 2, 2023
@rstoyanchev rstoyanchev self-assigned this Oct 2, 2023
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

3 participants