fix: libpaket: add more headers to tracking search

This commit is contained in:
jane400 2024-09-18 17:05:27 +02:00 committed by jane400
parent ff66184471
commit d122cfc065

View file

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{login::DHLIdToken, LibraryError, LibraryResult}; use crate::{constants::web_user_agent, login::DHLIdToken, LibraryResult};
#[derive(Default)] #[derive(Default)]
pub struct TrackingParams { pub struct TrackingParams {
@ -19,30 +19,38 @@ impl crate::WebClient {
&self, &self,
params: TrackingParams, params: TrackingParams,
ids: Vec<String>, ids: Vec<String>,
dhli: Option<&DHLIdToken>, dhli: &DHLIdToken,
) -> LibraryResult<Vec<Shipment>> { ) -> LibraryResult<Vec<Shipment>> {
let api_key = crate::www::api_key_header(); let api_key = crate::www::api_key_header();
let res = if let Some(dhli) = dhli {
let cookie_value = crate::utils::CookieHeaderValueBuilder::new() let cookie_value = crate::utils::CookieHeaderValueBuilder::new()
.add_dhli(&dhli) .add_dhli(&dhli)
.add_dhlcs(&dhli) .add_dhlcs(&dhli)
.build_string(); .build_string();
request!(
let res = request!(
self.web_client, self.web_client,
endpoint_data_search, endpoint_data_search,
query(&query_parameters_data_search(&params, ids)), query(&query_parameters_data_search(&params, ids)),
header(api_key.0, api_key.1), header(api_key.0, api_key.1),
header("cookie", cookie_value), header("cookie", cookie_value),
header("accept-language", "de-DE;q=1.0"),
header("x-requested-with", "de.dhl.paket"), header("x-requested-with", "de.dhl.paket"),
header("sec-ch-ua-platform", "\"Android\""), header("sec-ch-ua-platform", "\"Android\""),
header("sec-ch-ua", r#""Chromium";v="122", "Not(A:Brand";v="24", "Android WebView";v="122""#), header(
"sec-ch-ua",
r#""Chromium";v="122", "Not(A:Brand";v="24", "Android WebView";v="122""#
),
header("sec-ch-ua-mobile", "?1"), header("sec-ch-ua-mobile", "?1"),
header("accept", "application/json"),
header("content-type", "application/json"), header("content-type", "application/json"),
header("accept", "application/json") header(
) "referer",
} else { "https://www.dhl.de/int-static/pdapp/spa/prod/ver5-SPA-VERFOLGEN.html"
return Err(LibraryError::InvalidArgument("only supported with a logged-in session".to_string())); ),
}; header("verfolgen-wg", "0"),
header("user-agent", web_user_agent()),
headers(crate::www::web_headers())
);
let resp = parse_json_response!(res, Response); let resp = parse_json_response!(res, Response);
resp.into() resp.into()