Skip to content

Modify request before retrying #102

@Jericho

Description

@Jericho

Currently the FluentHttpClient allows us to handle scenarios where a request fails (presumably due to a transient problem) and waiting a brief moment allows us to dispatch the exact same request. An example is when you exceed the number of requests that an API allows you to make in a given period of time. In this scenario, you can typically reissue the exact same request after waiting a second or two. This is working quite well.

However, there are more advanced scenarios that I feel FluentHttpClient is not allowing us to handle. Let me offer an example to illustrate what I mean: let's say we issue a request with a "bearer" authentication token and the response is HTTP 401 due to the token being expired. I can write a custom IRetryConfig that will automatically refresh the token, the ShouldRetry in my IRetryConfig class will return true to indicate that I want the request to be retried but I have no way of replacing the expired token with the new token. Again, this is just an example. What I'm trying to illustrate is a scenario where I need the request to be slightly modified before being retried.

To kick-start the discussion about how to handle this kind of scenarios, I would like to propose adding an additional parameter to the ShouldRetry and/or GetDelay methods in the IRetry interface like so:

// Current signature:
bool ShouldRetry(HttpResponseMessage response);
TimeSpan GetDelay(int retry, HttpResponseMessage response);

// What I propose:
bool ShouldRetry(HttpResponseMessage response, IRequest request);
TimeSpan GetDelay(int retry, HttpResponseMessage response, IRequest request);

This would allow developers to modify the request in their implementation of the ShouldRetry and/or GetDelay methods prior to the request being reissued.

If you think my suggestion makes sense, I'll be happy to submit a PR.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions