(
agent: &ureq::Agent,
config: &HttpConfig,
id: HttpID,
request: HttpRequest,
)
| 515 | HttpMethod::Patch, |
| 516 | url, |
| 517 | HttpBody::Variant(body), |
| 518 | )) |
| 519 | } |
| 520 | |
| 521 | pub fn post_bytes(&mut self, url: impl Into<String>, body: Vec<u8>) -> HttpID { |
| 522 | self.request(HttpRequest::post_bytes(url, body)) |
| 523 | } |
| 524 | |
| 525 | pub fn poll(&mut self) -> Option<HttpEvent> { |
| 526 | if let Some(event) = self.local_events.pop_front() { |
| 527 | return Some(event); |
| 528 | } |
| 529 | self.rx.try_recv().ok() |
| 530 | } |
| 531 | |
| 532 | pub fn poll_all(&mut self, max_events: usize) -> Vec<HttpEvent> { |
| 533 | let mut out = Vec::new(); |
| 534 | for _ in 0..max_events { |
| 535 | let Some(event) = self.poll() else { |
| 536 | break; |
| 537 | }; |
| 538 | out.push(event); |
| 539 | } |
| 540 | out |
| 541 | } |
| 542 | |
| 543 | pub fn config(&self) -> &HttpConfig { |
| 544 | &self.config |
| 545 | } |
| 546 | |
| 547 | pub fn queue_config(&self) -> HttpQueueConfig { |
| 548 | self.queue_config |
| 549 | } |
| 550 | |
| 551 | pub fn rejected_requests(&self) -> u64 { |
| 552 | self.rejected_requests |
| 553 | } |
| 554 | |
| 555 | fn next_http_id(&mut self) -> HttpID { |
| 556 | let id = HttpID(self.next_id); |
| 557 | self.next_id = self.next_id.wrapping_add(1); |
| 558 | id |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | impl Default for HttpClient { |
| 563 | fn default() -> Self { |
| 564 | Self::new() |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | fn http_worker( |
| 569 | config: HttpConfig, |
| 570 | work_rx: Arc<Mutex<Receiver<HttpWork>>>, |
| 571 | event_tx: SyncSender<HttpEvent>, |
| 572 | shared_agent: Option<ureq::Agent>, |
| 573 | ) { |
| 574 | loop { |
no test coverage detected