mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-04-18 07:57:59 +02:00
Use url::Url::parse
to check the url
This commit is contained in:
parent
c2ff4dd3b2
commit
7ca2a8eb6f
@ -119,10 +119,22 @@ pub struct Network {
|
|||||||
impl Remote {
|
impl Remote {
|
||||||
pub fn try_into_db_node(self, name: &str) -> Result<DbRemote, ResponseError> {
|
pub fn try_into_db_node(self, name: &str) -> Result<DbRemote, ResponseError> {
|
||||||
Ok(DbRemote {
|
Ok(DbRemote {
|
||||||
url: self.url.set().ok_or(ResponseError::from_msg(
|
url: self
|
||||||
format!("Missing field `.remotes.{name}.url`"),
|
.url
|
||||||
meilisearch_types::error::Code::MissingNetworkUrl,
|
.set()
|
||||||
))?,
|
.ok_or(ResponseError::from_msg(
|
||||||
|
format!("Missing field `.remotes.{name}.url`"),
|
||||||
|
meilisearch_types::error::Code::MissingNetworkUrl,
|
||||||
|
))
|
||||||
|
.and_then(|url| {
|
||||||
|
if let Err(error) = url::Url::parse(&url) {
|
||||||
|
return Err(ResponseError::from_msg(
|
||||||
|
format!("Invalid `.remotes.{name}.url` (`{url}`): {error}"),
|
||||||
|
meilisearch_types::error::Code::InvalidNetworkUrl,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(url)
|
||||||
|
})?,
|
||||||
search_api_key: self.search_api_key.set(),
|
search_api_key: self.search_api_key.set(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -212,11 +224,9 @@ async fn patch_network(
|
|||||||
let merged = DbRemote {
|
let merged = DbRemote {
|
||||||
url: match new_url {
|
url: match new_url {
|
||||||
Setting::Set(new_url) => {
|
Setting::Set(new_url) => {
|
||||||
if !new_url.starts_with("http://")
|
if let Err(error) = url::Url::parse(&new_url) {
|
||||||
&& !new_url.starts_with("https://")
|
|
||||||
{
|
|
||||||
return Err(ResponseError::from_msg(
|
return Err(ResponseError::from_msg(
|
||||||
format!("in .remotes.{key}.url: error from Url::parse"),
|
format!("Invalid `.remotes.{key}.url` (`{new_url}`): {error}"),
|
||||||
meilisearch_types::error::Code::InvalidNetworkUrl,
|
meilisearch_types::error::Code::InvalidNetworkUrl,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user