Skip to content

Client responses of HTTP conversations have mismatching requestΒ #13244

Closed as not planned

Description

@sbordet

Jetty version(s)
12.1.x

Description
Following up on this comment: #1445 (comment)

In case of HTTP conversations, for example redirects, request Rq1 gets a 302 Rs1, which triggers the internal HttpClient mechanism to follow the redirect and send request Rq2 that gets a 200 Rs2.

Rs1 and Rq2 are "internal" and what the application sees is Rq1 and Rs2, i.e. the request and the 200 response.

Unfortunately, calling Response.getRequest() from listeners when Rs2 is notified to listeners attached to Rq1 via e.g. Request.onResponseSuccess(), yields Rq2 instead of Rq1.

Activity

  1. added
    BugFor general bugs on Jetty side
    on Jun 13, 2025
  2. moved this to πŸ— In progress in Jetty 12.1.0 - (FROZEN)on Jun 13, 2025
  3. added a commit that references this issue on Jun 13, 2025
    797aa01
  4. sbordet commented on Jun 16, 2025

    @sbordet
    ContributorAuthor

    One other option is a new listener like that:

    httpClient.newRequest(...)
        .onConversation((prevResponse, nextRequest) -> ...)
        .onComplete(response -> response.getRequest() == <the last request, not the previous, not the first>)

    @lorban thoughts?

  5. lorban commented on Jun 18, 2025

    @lorban
    Contributor

    I don't like it, at least if we're looking for an answer to the original remark:

    It turns out that onComplete is invoked with a Result whose embedded Request object is not equal to the Request object that initiated the request (the URL and HTTP method are the same but the Request object is not). This means my code has no way of knowing that a previously-fired request has actually completed.

    In my view, making the onComplete() call with a response that links to the original request is a nice quality of life improvement that allows writing this kind of code:

    httpClient.newRequest(...)
        .onComplete(response -> { Request r = response.getRequest(); makeUseOf(r); })

    but you could still access the original request from onComplete by making the request code a bit uglier:

    Request r = httpClient.newRequest(...);
    r.onComplete(response -> { makeUseOf(r); })

    I fail to see what onConversation() would solve as you'd still need to complexify your code to access the original request and doesn't really bring anything useful in this context.

  6. moved this from πŸ— In progress to No status in Jetty 12.1.0 - (FROZEN)on Jul 2, 2025
  7. added and removed
    BugFor general bugs on Jetty side
    on Jul 2, 2025
  8. added this to Jetty 12.1.5 and removed this from Jetty 12.1.4 - FROZENon Nov 5, 2025
  9. added this to Jetty 12.1.6 - FROZEN and removed this from Jetty 12.1.5on Dec 1, 2025
  10. sbordet commented on Jan 7, 2026

    @sbordet
    ContributorAuthor

    Closing as per discussion in #13245.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions