Skip to content

Remove current_request_steps in Req.Request#255

Open
thenrio wants to merge 1 commit into
wojtekmach:mainfrom
thenrio:remove-current_request_steps
Open

Remove current_request_steps in Req.Request#255
thenrio wants to merge 1 commit into
wojtekmach:mainfrom
thenrio:remove-current_request_steps

Conversation

@thenrio

@thenrio thenrio commented Oct 6, 2023

Copy link
Copy Markdown

Just use request_steps.

@wojtekmach

Copy link
Copy Markdown
Owner

Thank you for the PR. It seems we are missing tests because the build should have failed as we needed this design for things like not replying base_url+url on retries, etc. I’ll investigate. Maybe it is not needed after all!

@thenrio

thenrio commented Oct 6, 2023

Copy link
Copy Markdown
Author

Sure! Cheers.

@wojtekmach

Copy link
Copy Markdown
Owner

Note to self: revisit Req.Request.prepare/1 while at it.

@thenrio thenrio force-pushed the remove-current_request_steps branch from b0b1a5d to b51f580 Compare March 27, 2024 10:31
@thenrio

thenrio commented Mar 27, 2024

Copy link
Copy Markdown
Author

Hi @wojtekmach, I noticed that Req.Request.run_request/1 "consumes" the current_request_steps:

run_request(%{request | current_request_steps: rest})
.

Then we don't run base_url or params twice on retry, such as in

test "does not re-encode params", c do
.
In fact, retry does not run any of the input request_steps, as current_request_steps is empty...

This commit "consumes" the request_steps, so we don't run base_url or params twice on retry.
We achieve same behavior with a list removed from memory and a lookup removed,

step = Keyword.fetch!(request.request_steps, step)
.

Cheers.

@wojtekmach wojtekmach force-pushed the main branch 4 times, most recently from 249b80c to 16991cd Compare May 28, 2024 10:40
@wojtekmach

wojtekmach commented Dec 30, 2024

Copy link
Copy Markdown
Owner

Sorry for delay, this is tricky because the whole reason we introduced :current_request_steps was to avoid this:

Req.new(params: [a: 1])
|> Req.Request.prepend_response_steps(
  # as if we don't have current_request_steps
  test: fn {req, resp} ->
    req = put_in(req.current_request_steps, Keyword.keys(req.request_steps))
    {req, resp}
  end
)
|> Req.get!(
  retry_delay: 10,
  plug: fn conn ->
    dbg(conn.query_string)
    # conn.query_string #=> "a=1"
    # conn.query_string #=> "a=1&a=1"
    # conn.query_string #=> "a=1&a=1&a=1"
    # conn.query_string #=> "a=1&a=1&a=1&a=1"
    Plug.Conn.send_resp(conn, 500, "")
  end
)

(#140)

But yes, on the flip side it causes #296.

I haven't made up my mind yet which way to go, apologies for the delay.

@wojtekmach

Copy link
Copy Markdown
Owner

Another data point: https://github.com/reisub/http_cookie/pull/3/files#diff-afcb5ad934b330c8e7ff684f4861d7a95409c5440099af7c8e47919b210f60c0R65.

@wojtekmach

Copy link
Copy Markdown
Owner

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants