CodingAleCR / http_interceptor

A lightweight, simple plugin that allows you to intercept request and response objects and modify them if desired.
MIT License
134 stars 67 forks source link

Being able to pause requests #92

Open vixez opened 2 years ago

vixez commented 2 years ago

Is your feature request related to a problem? Please describe. The app I'm building can fire multiple requests at once. When one of the requests gets a 401 for an expired token, it updates the token in a RetryPolicy. During this update, all other requests should be paused as a new token is being retrieved.

Describe the solution you'd like Be able to pause requests in the queue, and resume them. For example pausing the queue when a new token is being retrieved. After the token is updated, all requests in the queue should have their interceptRequest method called, so the request can be updated with the new token (if an old token is in the request).

An alternative would be that everything runs in a sequence, no simultaneous requests.

vixez commented 2 years ago

I have created a PR for how I currently solved this issue.

CodingAleCR commented 2 years ago

Really interesting FR (Feature Request). Is this request based on the need for having multiple requests but refresh token only once for all subsequent requests?

CodingAleCR commented 2 years ago

This could be interesting as well if the "pausing" was performed when the retry policy is triggered instead of always as well, in any case, how would you feel about this?

vixez commented 2 years ago

Hey, Yes, we use the client to talk to our own backend. So when one of the requests returns a 401 all future requests should wait until the token is refreshed. If the token fails to refresh it could be nice to cancel further requests, since they will fail anyway without a token.

Maybe requests could be 'grouped' by a GUID, or adding tags to requests. With some way to cancel requests that belong to a certain group/tag. This would be convenient to cancel pending requests when a user is logged out due to an expired token, and cancel pending requests that user authentication. Se that group or tag would be cancelled then.

vixez commented 2 years ago

@CodingAleCR I have created a PR with how I implemented it in my app (both the limiting and pausing of requests), albeit a bit more abstract.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

shinayser commented 1 year ago

Hey @CodingAleCR please take a look on this issue. The bot seems not not like it and keeps closing xD

brxxxx commented 1 year ago

Any developments on this feature?

CodingAleCR commented 1 year ago

There's a PR outdated that deals with pooling requests and working on pauses. But other than that there's no current development at the moment.

Feel free to drop a PR with an implementation if that's something you think could help šŸ˜‰šŸ‘ŒšŸ¼

Thank you both for bringing this up as well!

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.