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

Use a pool for connections #93

Closed vixez closed 2 years ago

vixez commented 2 years ago

I needed a way to make requests run in a sequence, not parallel. This is more explained in the issue here.

The changes here introduce a Pool, so you can limit the amount of active requests by setting maxActiveRequests. By default this is 32, feel free to change this or skip the pool altogether if not set.

This code for example will make sure all requests, including for example retrieving a token in a RetryPolicy will run one by one.

return InterceptedClient.build(
    interceptors: [
        ApiLoggingInterceptor(),
        AuthenticationInterceptor(),
    ],
    requestTimeout: HTTP_TIMEOUT,
    retryPolicy: NewTokenRetryPolicy(),
    maxActiveRequests: 1,
);

To get a token in RetryPolicy I use a seperate InterceptedClient which is also limited to one request.

CodingAleCR commented 2 years ago

Hey, thanks for the contribution, I'll take a closer look soon, but in the meantime:

vixez commented 2 years ago

Improved PR: https://github.com/CodingAleCR/http_interceptor/pull/96

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.