Skip to content

Commit

Permalink
Use better way to print Cookie header
Browse files Browse the repository at this point in the history
  • Loading branch information
lifegpc authored Jul 3, 2024
1 parent ee79a97 commit a4a8f25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/cookies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ impl Cookie {
))
}

pub fn name(&self) -> &str {
&self._name
}

/// Get name and value string: name=value;
pub fn get_name_value(&self) -> String {
format!("{}={};", self._name.as_str(), self._value.as_str())
Expand Down
7 changes: 6 additions & 1 deletion src/webclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,19 @@ impl ToHeaders for JsonValue {
pub fn gen_cookie_header<U: IntoUrl>(c: &WebClient, url: U) -> String {
c.get_cookies_as_mut().jar.get_mut().check_expired();
let mut s = String::from("");
let mut k = String::from("");
let u = url.as_str();
for a in c.get_cookies().jar.get_ref().iter() {
if a.matched(u) {
if s.len() > 0 {
s += " ";
k += ", ";
}
s += a.get_name_value().as_str();
k += a.name();
}
}
log::debug!(target: "webclient", "Cookie List: {}", k);
s
}

Expand Down Expand Up @@ -373,7 +377,6 @@ impl WebClient {
let c = gen_cookie_header(&self, s);
if c.len() > 0 {
r = r.header("Cookie", c.as_str());
log::debug!(target: "webclient", "Cookie: {}", c.as_str());
}
self.handle_req_middlewares(r.build()?)
}
Expand Down Expand Up @@ -445,12 +448,14 @@ impl WebClient {
let mut r = self.client.post(s);
for (k, v) in self.get_headers().iter() {
r = r.header(k, v);
log::debug!(target: "webclient", "{}: {}", k, v);
}
let headers = headers.to_headers();
if headers.is_some() {
let h = headers.unwrap();
for (k, v) in h.iter() {
r = r.header(k, v);
log::debug!(target: "webclient", "{}: {}", k, v);
}
}
let c = gen_cookie_header(&self, s);
Expand Down

0 comments on commit a4a8f25

Please sign in to comment.