uv icon indicating copy to clipboard operation
uv copied to clipboard

feat: add custom middleware

Open tdejager opened this issue 9 months ago • 5 comments

Summary

This adds the ability to the RegistryClient and BaseClient for the consumer of the library to add custom middleware. The problem is that we have different authentication methods/requirements for pypi registries and would like to use the middleware provided by https://github.com/mamba-org/rattler

I've decided that if you do this, it overrides the normal middleware. This makes the retries option, and maybe some others, not really do anything anymore. Which is a bit weird, but couldn't directly think of a better way to do it, as you might end up with 'duplicated' middleware maybe.

This should close the issue/question I made: https://github.com/astral-sh/uv/issues/3400

I'll make it a draft for now because I do not know how you feel about such a change and maybe there is a different design you have in mid.

Test Plan

Once, I can update to the latest uv version, I'll try and test things out directly in: https://github.com/prefix-dev/pixi. I'm happy to add rust test here if you know a good place for it.

tdejager avatar May 10 '24 08:05 tdejager

Sorry for not replying to the initial issue! Yes we can support. What do you think about the branch in https://github.com/astral-sh/uv/compare/konsti/custom-middleware ? It's similar to yours but encapsulates the stack selection into MiddlewareStack.

Am i correct to assume you don't care about middleware for the offline case?

konstin avatar May 13 '24 17:05 konstin

Hi Konsti, that looks a lot better actually! Good question about the offline, our middleware does not account for it yet, but if you feel it's better to add it to the offline case as well, that seems totally valid!

tdejager avatar May 14 '24 06:05 tdejager

(force-pushing because i had to rebase on main, your initial commit should be preserved)

konstin avatar May 14 '24 09:05 konstin

@zanieb - do you want to review this?

charliermarsh avatar May 22 '24 02:05 charliermarsh

Sure

zanieb avatar May 22 '24 02:05 zanieb

Hi all, just wondering if you guys are happy with the current design, and if rebasing is the only requirement for this PR to be merged?

olivier-lacroix avatar Jul 09 '24 05:07 olivier-lacroix

Sorry, I need to review the latest implementation but am prioritizing things that impact more users right now.

zanieb avatar Jul 19 '24 17:07 zanieb

No worries. Thanks @zanieb !

olivier-lacroix avatar Jul 20 '24 00:07 olivier-lacroix

Is this still needed?

zanieb avatar Sep 16 '24 22:09 zanieb

Would still be very useful for us, however, as reqwest-middleware is now a forked version, I'm unsure regarding the compatibilities with the open-source version. However, we could re-vendor the middleware if needed :)

tdejager avatar Sep 17 '24 08:09 tdejager

It looks like @konstin added AuthIntegration::NoAuthMiddleware allowing the auth middleware to be disabled so maybe we just need the ability to attach extra middleware now?

zanieb avatar Oct 01 '24 17:10 zanieb

Sounds good, is there something you like me to change other than a rebase?

tdejager avatar Oct 01 '24 18:10 tdejager

Can we drop all the MiddlewareStack stuff and just add a extra_middleware: Vec<Arc<dyn Middleware>> option? Or is there more that you need?

zanieb avatar Oct 01 '24 18:10 zanieb

Not at all computer currently but sounds good to me, let me give it a go at the end of the week!

tdejager avatar Oct 01 '24 18:10 tdejager