Commit 8efefb189e
Unsigned
Layout: unified · split
src/server.rs +40 −5
| @@ -48,6 +48,7 @@ pub enum ServerMessage { | |||
| 48 | #[derive(Default)] | 48 | #[derive(Default)] |
| 49 | pub struct ServerSettings { | 49 | pub struct ServerSettings { |
| 50 | homeserver: Option<Url>, | 50 | homeserver: Option<Url>, |
| 51 | proxy: Option<Url>, | ||
| 51 | autoconnect: bool, | 52 | autoconnect: bool, |
| 52 | } | 53 | } |
| 53 | 54 | ||
| @@ -167,6 +168,7 @@ impl MatrixServer { | |||
| 167 | .expect("Can't create autoconnect option"); | 168 | .expect("Can't create autoconnect option"); |
| 168 | 169 | ||
| 169 | let server = server_copy; | 170 | let server = server_copy; |
| 171 | let server_copy = server.clone(); | ||
| 170 | 172 | ||
| 171 | let homeserver = | 173 | let homeserver = |
| 172 | StringOptionSettings::new(format!("{}.homeserver", server_name)) | 174 | StringOptionSettings::new(format!("{}.homeserver", server_name)) |
| @@ -187,7 +189,7 @@ impl MatrixServer { | |||
| 187 | let mut server = server_ref.borrow_mut(); | 189 | let mut server = server_ref.borrow_mut(); |
| 188 | let homeserver = Url::parse(option.value().as_ref()).expect( | 190 | let homeserver = Url::parse(option.value().as_ref()).expect( |
| 189 | "Can't parse homeserver URL, did the check callback fail?", | 191 | "Can't parse homeserver URL, did the check callback fail?", |
| 190 | ); | 192 | ); |
| 191 | 193 | ||
| 192 | server.settings.homeserver = Some(homeserver) | 194 | server.settings.homeserver = Some(homeserver) |
| 193 | }); | 195 | }); |
| @@ -195,6 +197,35 @@ impl MatrixServer { | |||
| 195 | server_section | 197 | server_section |
| 196 | .new_string_option(homeserver) | 198 | .new_string_option(homeserver) |
| 197 | .expect("Can't create homeserver option"); | 199 | .expect("Can't create homeserver option"); |
| 200 | |||
| 201 | let server = server_copy; | ||
| 202 | |||
| 203 | let proxy = StringOptionSettings::new(format!("{}.proxy", server_name)) | ||
| 204 | .set_check_callback(|_, _, value| { | ||
| 205 | if value.is_empty() { | ||
| 206 | true | ||
| 207 | } else { | ||
| 208 | MatrixServer::parse_homeserver_url(value.to_string()) | ||
| 209 | .is_ok() | ||
| 210 | } | ||
| 211 | }) | ||
| 212 | .set_change_callback(move |_, option| { | ||
| 213 | let server = server.clone(); | ||
| 214 | let server_ref = server | ||
| 215 | .upgrade() | ||
| 216 | .expect("Server got deleted while server config is alive"); | ||
| 217 | |||
| 218 | let mut server = server_ref.borrow_mut(); | ||
| 219 | let proxy = Url::parse(option.value().as_ref()).expect( | ||
| 220 | "Can't parse proxy URL, did the check callback fail?", | ||
| 221 | ); | ||
| 222 | |||
| 223 | server.settings.proxy = Some(proxy) | ||
| 224 | }); | ||
| 225 | |||
| 226 | server_section | ||
| 227 | .new_string_option(proxy) | ||
| 228 | .expect("Can't create proxy option"); | ||
| 198 | } | 229 | } |
| 199 | 230 | ||
| 200 | pub fn connected(&self) -> bool { | 231 | pub fn connected(&self) -> bool { |
| @@ -290,10 +321,14 @@ impl InnerServer { | |||
| 290 | self.settings.homeserver.as_ref().ok_or_else(|| { | 321 | self.settings.homeserver.as_ref().ok_or_else(|| { |
| 291 | ServerError::StartError("Homeserver not configured".to_owned()) | 322 | ServerError::StartError("Homeserver not configured".to_owned()) |
| 292 | })?; | 323 | })?; |
| 293 | let client_config = AsyncClientConfig::new() | 324 | |
| 294 | .proxy("http://localhost:8080") | 325 | let mut client_config = AsyncClientConfig::new(); |
| 295 | .unwrap() | 326 | |
| 296 | .disable_ssl_verification(); | 327 | if let Some(proxy) = &self.settings.proxy { |
| 328 | client_config = client_config.proxy(proxy.as_str()) | ||
| 329 | .unwrap() | ||
| 330 | .disable_ssl_verification(); | ||
| 331 | } | ||
| 297 | 332 | ||
| 298 | let client = AsyncClient::new_with_config( | 333 | let client = AsyncClient::new_with_config( |
| 299 | homeserver.clone(), | 334 | homeserver.clone(), |