(&self)
| 142 | |
| 143 | impl PublishArgs { |
| 144 | pub fn parse(&self) -> Result<ClientEndpoint> { |
| 145 | let auth = self.auth.unwrap_or(if self.protocol == Protocol::Webdav { |
| 146 | Auth::Basic |
| 147 | } else { |
| 148 | Auth::None |
| 149 | }); |
| 150 | if self.address.contains("://") { |
| 151 | let url = url::Url::parse(&self.address).context(crate::t!("invalid-url"))?; |
| 152 | let local_proto = |
| 153 | Protocol::from_str(url.scheme()).context(crate::t!("invalid-protocol"))?; |
| 154 | let local_addr = url.host_str().unwrap().to_string(); |
| 155 | let local_port = url |
| 156 | .port() |
| 157 | .or_else(|| self.protocol.default_port()) |
| 158 | .context(crate::t!("port-required"))?; |
| 159 | let mut local_path = url.path().to_string(); |
| 160 | if url.query().is_some() { |
| 161 | local_path.push('?'); |
| 162 | local_path.push_str(url.query().unwrap()); |
| 163 | } |
| 164 | let mut username = String::new(); |
| 165 | if !url.username().is_empty() { |
| 166 | username = url.username().to_string(); |
| 167 | } |
| 168 | let mut password = MaskedString(String::new()); |
| 169 | if let Some(pass) = url.password() { |
| 170 | password = MaskedString(pass.to_string()); |
| 171 | } |
| 172 | let mut filter_rules = self.rules.clone(); |
| 173 | for (index, rule) in filter_rules.iter_mut().enumerate() { |
| 174 | rule.order = index as i32; |
| 175 | } |
| 176 | |
| 177 | Ok(ClientEndpoint { |
| 178 | description: self.name.clone(), |
| 179 | local_proto: local_proto.into(), |
| 180 | local_addr, |
| 181 | local_port: local_port as u32, |
| 182 | local_path, |
| 183 | nodelay: Some(true), |
| 184 | auth: auth.into(), |
| 185 | acl: self.acl.clone(), |
| 186 | headers: self.headers.clone(), |
| 187 | filter_rules, |
| 188 | username, |
| 189 | password: password.0, |
| 190 | proxy_protocol: 0, // ProxyProtocolNone |
| 191 | }) |
| 192 | } else { |
| 193 | let (local_addr, local_port, local_path) = match self.protocol { |
| 194 | Protocol::OneC | Protocol::Minecraft | Protocol::Webdav => { |
| 195 | (self.address.clone(), 0, String::new()) |
| 196 | } |
| 197 | |
| 198 | Protocol::Http |
| 199 | | Protocol::Https |
| 200 | | Protocol::Tcp |
| 201 | | Protocol::Udp |
no test coverage detected