Follow jmap redirections to same host in cli (#1735)

Fixes #1734
This commit is contained in:
Renato Caldas 2025-06-28 08:19:00 +01:00 committed by GitHub
parent 0ef711fc3c
commit a9fbfc2a8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 6 deletions

View file

@ -17,7 +17,7 @@ use jmap_client::client::Credentials;
use modules::{
UnwrapResult,
cli::{Cli, Client, Commands},
is_localhost,
host, is_localhost,
};
use reqwest::{Method, StatusCode, header::AUTHORIZATION};
use serde::{Deserialize, Serialize, de::DeserializeOwned};
@ -191,6 +191,7 @@ impl Client {
jmap_client::client::Client::new()
.credentials(self.credentials)
.accept_invalid_certs(is_localhost(&self.url))
.follow_redirects([host(&self.url).expect("Invalid host").to_owned()])
.timeout(Duration::from_secs(self.timeout.unwrap_or(60)))
.connect(&self.url)
.await

View file

@ -235,13 +235,16 @@ pub async fn name_to_id(client: &Client, name: &str) -> String {
}
}
pub fn is_localhost(url: &str) -> bool {
pub fn host(url: &str) -> Option<&str> {
url.split_once("://")
.map(|(_, url)| url.split_once('/').map_or(url, |(host, _)| host))
.is_some_and(|host| {
let host = host.rsplit_once(':').map_or(host, |(host, _)| host);
host == "localhost" || host == "127.0.0.1" || host == "[::1]"
})
}
pub fn is_localhost(url: &str) -> bool {
host(url).is_some_and(|host| {
let host = host.rsplit_once(':').map_or(host, |(host, _)| host);
host == "localhost" || host == "127.0.0.1" || host == "[::1]"
})
}
pub trait OAuthResponse {