Skip to content

Commit

Permalink
fix: tls feature
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Oct 19, 2024
1 parent 76289cd commit bac14b1
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ pub(crate) mod util;
/// Tested for ZTE MF289F Gigacube
///
pub struct ZteClient {
referer: String,
target: String,
client: reqwest::Client,
}

impl ZteClient {
pub fn new(ip: &str) -> Result<Self> {
let client = reqwest::ClientBuilder::new().cookie_store(true).build()?;

#[cfg(any(feature = "ssl-native", feature = "ssl-rustls"))]
let referer = format!("https://{}/", ip);
#[cfg(not(any(feature = "ssl-native", feature = "ssl-rustls")))]
let referer = format!("http://{}/", ip);
#[cfg(any(feature = "tls-native", feature = "tls-rustls"))]
let target = format!("https://{}/", ip);
#[cfg(not(any(feature = "tls-native", feature = "tls-rustls")))]
let target = format!("http://{}/", ip);

Ok(ZteClient { referer, client })
Ok(ZteClient { target, client })
}

pub async fn login(&mut self, password: String) -> Result<()> {
Expand Down Expand Up @@ -294,11 +294,11 @@ impl ZteClient {
let form_data = serde_urlencoded::to_string(&wrapped_command)
.context(format!("Failed to serialize command: {}", goform_id))?;

let url = format!("{}goform/goform_set_cmd_process", self.referer);
let url = format!("{}goform/goform_set_cmd_process", self.target);
let request = self
.client
.post(&url)
.header(REFERER, &self.referer)
.header(REFERER, &self.target)
.header(
CONTENT_TYPE,
"application/x-www-form-urlencoded; charset=UTF-8",
Expand Down Expand Up @@ -327,15 +327,15 @@ impl ZteClient {
let multi_data = cmd.contains(",");
let url = format!(
"{}goform/goform_get_cmd_process?isTest=false&cmd={}{}",
self.referer,
self.target,
cmd,
if multi_data { "&multi_data=1" } else { "" }
);

let response = self
.client
.get(&url)
.header(REFERER, &self.referer)
.header(REFERER, &self.target)
.send()
.await
.context(format!("Failed to fetch command {}", cmd))?
Expand Down

0 comments on commit bac14b1

Please sign in to comment.