Skip to main content

codetether_browser/browser/offline/
auth_trace.rs

1//! Walk an HTTP redirect chain, carry cookies hop-to-hop via tetherscript
2//! BrowserSession's jar, emit JSON trace.
3
4use anyhow::Result;
5
6use super::auth_trace_run;
7use super::cookie_parse::CookieRecord;
8
9#[derive(Debug, serde::Serialize)]
10pub struct AuthTrace {
11    pub final_url: String,
12    pub redirect_count: usize,
13    pub truncated: bool,
14    pub steps: Vec<Step>,
15    pub cookies_after: Vec<CookieRecord>,
16}
17
18#[derive(Debug, serde::Serialize)]
19pub struct Step {
20    pub method: String,
21    pub url: String,
22    pub status: u16,
23    pub location: Option<String>,
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub cookie_header_sent: Option<String>,
26    pub set_cookies: Vec<CookieRecord>,
27}
28
29pub fn run(url: &str, max_redirects: u8) -> Result<String> {
30    let trace = auth_trace_run::walk(url, max_redirects)?;
31    Ok(serde_json::to_string_pretty(&trace)?)
32}
33
34pub(crate) fn resolve(base: &str, location: &str) -> String {
35    reqwest::Url::parse(base)
36        .and_then(|b| b.join(location))
37        .map(|u| u.to_string())
38        .unwrap_or_else(|_| location.to_string())
39}