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

feat: redirect #603

Merged
merged 38 commits into from
Mar 27, 2021
Merged

feat: redirect #603

merged 38 commits into from
Mar 27, 2021

Conversation

ronag
Copy link
Member

@ronag ronag commented Mar 22, 2021

Continuing on from: #600

Trying to figure out the API. Doing this through Agent or Pool doesn't quite make sense IMO.

@ronag ronag requested a review from mcollina March 22, 2021 10:36
@ronag ronag force-pushed the redirect3 branch 2 times, most recently from b782ebe to 1036b2c Compare March 22, 2021 10:39
@codecov-io
Copy link

codecov-io commented Mar 22, 2021

Codecov Report

Merging #603 (240079c) into main (b3dd69f) will decrease coverage by 0.99%.
The diff coverage is 83.33%.

❗ Current head 240079c differs from pull request most recent head b797c93. Consider uploading reports for the commit b797c93 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #603      +/-   ##
==========================================
- Coverage   99.10%   98.10%   -1.00%     
==========================================
  Files          17       18       +1     
  Lines        1446     1529      +83     
==========================================
+ Hits         1433     1500      +67     
- Misses         13       29      +16     
Impacted Files Coverage Δ
lib/client-pool.js 98.65% <50.00%> (-0.67%) ⬇️
lib/core/client.js 98.97% <50.00%> (-0.17%) ⬇️
lib/agent/index.js 89.85% <79.31%> (ø)
lib/agent/redirect.js 85.71% <85.71%> (ø)
index.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b3dd69f...b797c93. Read the comment docs.

@mcollina
Copy link
Member

We are not in agreement. Using an Agent will make adding redirect being transparent for fetch() and other high-level libraries. Adding a different API would provide a worse developer experience (however it would be a simpler implementation).

@ronag
Copy link
Member Author

ronag commented Mar 22, 2021

Hm. I agree it would be nicer to implement this just as another client and/or agent. I just don’t see how to implement this in a way that makes sense in that way.

I have some more ideas here regarding developer experience so I’ll continue working on this and see if we can reach an agreement.

@ronag
Copy link
Member Author

ronag commented Mar 22, 2021

Agent would have to return a redirect client which would have to have a reference to the agent.

Then the client needs to correctly implement all the client APIs. Many of which would not make much sense. Especially with cross origin in mind. Would have to give that more thought but it start to feel like code smell if it’s that complicated to add something this simple.

@ronag ronag closed this Mar 22, 2021
@ronag ronag reopened this Mar 22, 2021
@ronag
Copy link
Member Author

ronag commented Mar 22, 2021

@mcollina PTAL. Has a change to the Agent API to enable better composition.

@ronag
Copy link
Member Author

ronag commented Mar 22, 2021

@ShogunPanda

lib/redirect-agent.js Outdated Show resolved Hide resolved
lib/redirect-agent.js Outdated Show resolved Hide resolved
lib/redirect-agent.js Outdated Show resolved Hide resolved
@ShogunPanda
Copy link
Contributor

@ronag I like the API. Nice work.
I would suggest to copy tests from my PR, adapt them (basically replacing RedirectPool with RedirectAgent and see it they passes.

lib/redirect-agent.js Outdated Show resolved Hide resolved
@ronag
Copy link
Member Author

ronag commented Mar 22, 2021

I would suggest to copy tests from my PR, adapt them (basically replacing RedirectPool with RedirectAgent and see it they passes.

Yes, I was hoping we could collaborate on the tests. I'll port them over from your PR once we know whether @mcollina agrees on the approach.

@ShogunPanda
Copy link
Contributor

I would suggest to copy tests from my PR, adapt them (basically replacing RedirectPool with RedirectAgent and see it they passes.

Yes, I was hoping we could collaborate on the tests. I'll port them over from your PR once we know whether @mcollina agrees on the approach.

Wonderful! ^^

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach looks good to me, I've left a comment.

lib/agent.js Outdated Show resolved Hide resolved
@ronag ronag mentioned this pull request Mar 22, 2021
@ronag ronag force-pushed the redirect3 branch 4 times, most recently from 99df977 to 25a1ab3 Compare March 22, 2021 21:53
@ronag ronag requested review from mcollina and dnlup March 22, 2021 21:53
@ronag
Copy link
Member Author

ronag commented Mar 22, 2021

I think this is as much as I can do at the moment. @ShogunPanda do you think you could help out with test coverage and docs? @Ethan-Arrowood maybe you could also help with docs?

Basically what we now have architecture wise is:

interface Dispatcher implements EventEmitter {
  dispatch (opts, handler)
  close ()
  destroy ()
  destroyed
  closed
  events: 'connect', 'disconnect'
}

class Agent implements Dispatcher {
}

class RedirectAgent implements Dispatcher {
}

interface Client implement Dispatcher {
  url
  pipelining
  connected
  pending
  running
  size
  busy
  events: 'drain'
}

class Pool implements Client {
}

So basically we have two traits Dispatcher implements EventEmitter and Client implements Dispatcher. Where client is just a dispatcher with a public prop interface.

@ronag ronag force-pushed the redirect3 branch 3 times, most recently from 9406311 to 8620702 Compare March 22, 2021 22:05
@ronag
Copy link
Member Author

ronag commented Mar 24, 2021

Should we merge RedirectAgent into Agent? The functionality is kind of trivial and it would have to be explicitly enabled by passing the maxRedirects option in the constructor.

@mcollina @dnlup @ShogunPanda wdyt?

@ShogunPanda
Copy link
Contributor

I agree.
Since it's a very common use case when dealing with HTTP agents, it's better to keep things simple for developer experience (in this case, not having to remember to use a different agent for a comon case).
And since it's protected by maxRedirects I don't see performance problems.

Also, I have to agree since it was similar to my original proposal in #553 (comment). Just joking. Lol.

@mcollina
Copy link
Member

Good for me!

@ronag
Copy link
Member Author

ronag commented Mar 24, 2021

Done!

@ronag
Copy link
Member Author

ronag commented Mar 24, 2021

This is starting to feel pretty solid. Just waiting for docs + test coverage. @Ethan-Arrowood @ShogunPanda.

lib/agent/redirect.js Outdated Show resolved Hide resolved
@ShogunPanda
Copy link
Contributor

@ronag @mcollina

I've sent #621 which brings coverage back to 100%.
It also fixes couple of minor stuffs. Please let me know what you think about it.

@ShogunPanda
Copy link
Contributor

Also, final note. Once this get merged, I'll start working on #615.

ShogunPanda and others added 2 commits March 26, 2021 22:25
* fix: Allow to connect to IPv6 addresses.

* fix: Removed alleged dead code.

* test: Brought back test coverage to 100%.

* fix: Readded needed hooks.

* test: Removed unneeded ignores.
@ronag ronag merged commit 858a0f4 into main Mar 27, 2021
@Uzlopak Uzlopak deleted the redirect3 branch February 21, 2024 12:39
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
* feat: redirect

* fixup: docs

* fixup: docs

* fixup: docs

* fixup

* fixup

* fixup

* fixup

* fixup-n

* fixup

* fixup

* fixup

* fixp

* fixup

* Update lib/core/client.js

Co-authored-by: Ethan Arrowood <ethan.arrowood@gmail.com>

* Update lib/client-pool.js

Co-authored-by: Ethan Arrowood <ethan.arrowood@gmail.com>

* fixup: redirectpool fetch global agent on every dispatch call

* fixup: reduce Agent api

* fixup

* fixup

* Update lib/agent-redirect.js

* test: Added tests for RedirectAgent. (nodejs#614)

* fixup

* fixup

* fixup

* fixuP

* fixup

* fixup

* fixuP

* fixuP

* fixuP

* fixuP

* fixuP

* fixuP

* fixuP

* fixup

* Bring test coverage above 95% (nodejs#621)

* fix: Allow to connect to IPv6 addresses.

* fix: Removed alleged dead code.

* test: Brought back test coverage to 100%.

* fix: Readded needed hooks.

* test: Removed unneeded ignores.

Co-authored-by: Ethan Arrowood <ethan.arrowood@gmail.com>
Co-authored-by: Shogun <ShogunPanda@users.noreply.github.com>
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.

6 participants