(
&self,
py: Python<'python>,
method: &str,
url: String,
content: Option<Vec<u8>>,
mut data: Option<RequestBody>,
headers: Option<HashMap<String
| 370 | |
| 371 | #[pyo3(signature = (method, url, content=None, data=None, headers=None, timeout=Some(Right(USE_CLIENT_DEFAULT_SENTINEL)), force_http3=false, stream=false))] |
| 372 | pub fn request<'python>( |
| 373 | &self, |
| 374 | py: Python<'python>, |
| 375 | method: &str, |
| 376 | url: String, |
| 377 | content: Option<Vec<u8>>, |
| 378 | mut data: Option<RequestBody>, |
| 379 | headers: Option<HashMap<String, String>>, |
| 380 | timeout: Option<Either<f64, &str>>, |
| 381 | force_http3: Option<bool>, |
| 382 | stream: Option<bool>, |
| 383 | ) -> Result<pyo3::Bound<'python, PyAny>, PyErr> { |
| 384 | let mut headers = headers.clone(); |
| 385 | |
| 386 | if let Some(content) = content { |
| 387 | data = Some(RequestBody::Bytes(content)); |
| 388 | } |
| 389 | |
| 390 | let body: Vec<u8> = match data { |
| 391 | Some(data) => match data { |
| 392 | RequestBody::Bytes(bytes) => Ok(bytes), |
| 393 | RequestBody::Form(form) => { |
| 394 | headers.get_or_insert_with(HashMap::new).insert( |
| 395 | "Content-Type".to_string(), |
| 396 | "application/x-www-form-urlencoded".to_string(), |
| 397 | ); |
| 398 | Ok(form_to_bytes(form)) |
| 399 | } |
| 400 | RequestBody::CatchAll(e) => Err(PyErr::new::<PyTypeError, _>(format!( |
| 401 | "Unsupported data type in request body: {e:#?}" |
| 402 | ))), |
| 403 | }, |
| 404 | None => Ok(Vec::new()), |
| 405 | }?; |
| 406 | |
| 407 | let timeout = parse_timeout(timeout)?; |
| 408 | |
| 409 | let options = RequestOptions { |
| 410 | headers: headers |
| 411 | .unwrap_or_default() |
| 412 | .iter() |
| 413 | .map(|(k, v)| (k.clone(), v.clone())) |
| 414 | .collect(), |
| 415 | timeout, |
| 416 | http3_prior_knowledge: force_http3.unwrap_or(false), |
| 417 | }; |
| 418 | |
| 419 | let method_str = method.to_string(); |
| 420 | let default_encoding = self.default_encoding.clone(); |
| 421 | let stream_value = stream.unwrap_or(false); |
| 422 | let impit = Arc::clone(&self.impit); |
| 423 | |
| 424 | pyo3_async_runtimes::tokio::future_into_py::<_, ImpitPyResponse>(py, async move { |
| 425 | let response = match method_str.to_lowercase().as_str() { |
| 426 | "get" => impit.get(url, Some(body), Some(options)).await, |
| 427 | "post" => impit.post(url, Some(body), Some(options)).await, |
| 428 | "patch" => impit.patch(url, Some(body), Some(options)).await, |
| 429 | "put" => impit.put(url, Some(body), Some(options)).await, |
no test coverage detected