blob: cd8b645d0d149bab5feeaa5e67aa654abf194675 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
use crate::http_client::HttpClient;
use anyhow::{bail, Result};
pub const PROFILE_URL: &str = "https://learning.oreilly.com/profile/";
/// Check whether cookies keep us logged in by fetching the profile page.
/// Returns:
/// - Ok(true) => HTTP 200 (assume logged in)
/// - Ok(false) => Redirect or 401/403 (assume not logged in)
/// - Err(..) => Network/other error
pub async fn check_login(client: &HttpClient) -> Result<bool> {
let res = client.client().get(PROFILE_URL).send().await?;
let status = res.status();
if status.is_redirection() {
Ok(false)
} else if status == 200 {
Ok(true)
} else {
bail!("Profile request returned unexpected status {}", status)
}
}
|