}
}
-pub fn execute_and_log_request(
- client: &reqwest::blocking::Client,
- req: reqwest::blocking::Request,
-) -> Result<(reqwest::blocking::Response, TransactionLogEntry), ClientError> {
- let method = req.method().clone();
- let url = req.url().clone();
- let mut req_headers = Vec::new();
- for h in req.headers() {
- req_headers.push(TransactionLogEntry::translate_header(h));
- }
-
- let rsp = client.execute(req)?;
- let status = rsp.status();
- let mut rsp_headers = Vec::new();
- for h in rsp.headers() {
- rsp_headers.push(TransactionLogEntry::translate_header(h));
- }
-
- let log = TransactionLogEntry {
- method,
- url,
- req_headers,
- status,
- rsp_headers,
- };
-
- Ok((rsp, log))
-}
-
const REDIRECT_MAGIC_STRING: &str = "urn:ietf:wg:oauth:2.0:oob";
const WEBSITE: &str =
"https://www.chiark.greenend.org.uk/~sgtatham/mastodonochrome/";
req.build(&base_url, client, self.auth.user_token.as_deref())
}
+ fn execute_and_log_request(
+ &self,
+ req: reqwest::blocking::Request,
+ ) -> Result<(reqwest::blocking::Response, TransactionLogEntry), ClientError>
+ {
+ let method = req.method().clone();
+ let url = req.url().clone();
+ let mut req_headers = Vec::new();
+ for h in req.headers() {
+ req_headers.push(TransactionLogEntry::translate_header(h));
+ }
+
+ let rsp = self.client.execute(req)?;
+ let status = rsp.status();
+ let mut rsp_headers = Vec::new();
+ for h in rsp.headers() {
+ rsp_headers.push(TransactionLogEntry::translate_header(h));
+ }
+
+ let log = TransactionLogEntry {
+ method,
+ url,
+ req_headers,
+ status,
+ rsp_headers,
+ };
+
+ Ok((rsp, log))
+ }
+
/// Sends and logs, but doesn't do any checking on the response
///
/// You must call `.is_success()` (or equivalent) on the response
req: Req,
) -> Result<(String, reqwest::blocking::Response), ClientError> {
let (urlstr, req) = self.api_request_cl(&self.client, req)?;
- let (rsp, log) = execute_and_log_request(&self.client, req.build()?)?;
+ let (rsp, log) = self.execute_and_log_request(req.build()?)?;
self.consume_transaction_log(log);
Ok((urlstr, rsp))
}
let client = reqwest_client()?;
let (url, mut req) = self.api_request_cl(&client, req)?;
- let (rsp, log) = execute_and_log_request(&self.client, req.build()?)?;
+ let (rsp, log) = self.execute_and_log_request(req.build()?)?;
self.consume_transaction_log(log);
let mut rsp = rsp;
if rsp.status().is_redirection() {
req = req.bearer_auth(token);
}
let (newrsp, log) =
- execute_and_log_request(&self.client, req.build()?)?;
+ self.execute_and_log_request(req.build()?)?;
self.consume_transaction_log(log);
rsp = newrsp;
}
}
}?;
let req = self.client.request(reqwest::Method::GET, url).build()?;
- let (rsp, log) = execute_and_log_request(&self.client, req)?;
+ let (rsp, log) = self.execute_and_log_request(req)?;
self.consume_transaction_log(log);
let rspstatus = rsp.status();
if rspstatus.is_redirection() || rspstatus.is_success() {