Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex whitelist feature #151

Closed
wants to merge 1 commit into from
Closed

Conversation

yourlogarithm
Copy link

@yourlogarithm yourlogarithm commented May 15, 2024

Adds a regex set matching feature so that if the request fails and the url matches against the provided whitelist pattern - it will be retried, otherwise not.

Example:

let whitelist = regex::RegexSet::new(vec!["foo", "bar"]).unwrap();
let reqwest_client = Client::builder().build().unwrap();
let client = ClientBuilder::new(reqwest_client)
    .with(RetryTransientMiddleware::new_with_policy(...).with_whitelist(whitelist))
    .build();

let resp = client
        .get("127.0.0.1/foo")
        .send()
        .await
        .expect("call failed"); // Will be retried if failed according to policy

let resp = client
        .get("127.0.0.1/bar")
        .send()
        .await
        .expect("call failed"); // Will be retried if failed according to policy
 
 let resp = client
        .get("127.0.0.1/something")
        .send()
        .await
        .expect("call failed");  // Will NOT be retried because the url does not match regex

@yourlogarithm yourlogarithm requested a review from a team as a code owner May 15, 2024 10:25
@yourlogarithm yourlogarithm changed the title added regex feature Regex whitelist feature May 15, 2024
@LukeMathWalker
Copy link
Collaborator

This feels way too specific to be a first-class feature in reqwest-retry.
But it points at an underlying issue: you can't implement this on your own because RetryableStrategy doesn't take into account the request. That's what we should be reasoning about imo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants