http_interceptor icon indicating copy to clipboard operation
http_interceptor copied to clipboard

Being able to pause requests

Open vixez opened this issue 4 years ago • 12 comments

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.

  • Request 1: Added to queue
  • Request 1: interceptRequest
  • Request 2: Added to queue
  • Request 1: 401 => RetryPolicy + pause all requests in the queue
  • Request 1: Asynchronously finish shouldAttemptRetryOnResponse (token in storage updated)
  • Request 1: Retry so > interceptRequest
  • Request 1: finish successfully
  • Request 2: interceptRequest
  • Request 2: finish successfully
  • ...

vixez avatar Oct 19 '21 13:10 vixez

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

  • https://github.com/CodingAleCR/http_interceptor/pull/93

vixez avatar Oct 19 '21 15:10 vixez

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 avatar Oct 22 '21 03:10 CodingAleCR

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?

CodingAleCR avatar Oct 22 '21 03:10 CodingAleCR

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 avatar Oct 25 '21 07:10 vixez

@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.

  • https://github.com/CodingAleCR/http_interceptor/pull/96

vixez avatar Oct 28 '21 09:10 vixez

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] avatar Dec 27 '21 13:12 stale[bot]

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] avatar Mar 09 '22 02:03 stale[bot]

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

shinayser avatar Jan 27 '23 14:01 shinayser

Any developments on this feature?

brxxxx avatar Feb 11 '23 07:02 brxxxx

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!

CodingAleCR avatar Feb 11 '23 07:02 CodingAleCR

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] avatar May 04 '23 00:05 stale[bot]

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] avatar Aug 10 '23 06:08 stale[bot]