qubit_http/options/
http_retry_method_policy.rs1use std::str::FromStr;
12
13use http::Method;
14use parse_display::FromStr as DeriveFromStr;
15use serde::{Deserialize, Serialize};
16
17use super::HttpConfigError;
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, DeriveFromStr)]
21#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
22pub enum HttpRetryMethodPolicy {
23 #[default]
25 #[display("IDEMPOTENT_ONLY")]
26 #[from_str(regex = "(?i)IDEMPOTENT_ONLY|IDEMPOTENT")]
27 IdempotentOnly,
28 #[display("ALL_METHODS")]
30 #[from_str(regex = "(?i)ALL_METHODS|ALL")]
31 AllMethods,
32 #[display("NONE")]
34 #[from_str(regex = "(?i)NONE|DISABLED")]
35 None,
36}
37
38impl HttpRetryMethodPolicy {
39 pub(super) fn from_config_value(value: &str) -> Result<Self, HttpConfigError> {
40 Self::from_str(value.trim()).map_err(|_| {
41 HttpConfigError::invalid_value(
42 "method_policy",
43 format!("Unsupported retry method policy: {value}"),
44 )
45 })
46 }
47
48 pub fn allows_method(&self, method: &Method) -> bool {
56 match self {
57 Self::IdempotentOnly => matches!(
58 *method,
59 Method::GET
60 | Method::HEAD
61 | Method::PUT
62 | Method::DELETE
63 | Method::OPTIONS
64 | Method::TRACE
65 ),
66 Self::AllMethods => true,
67 Self::None => false,
68 }
69 }
70}