| 583 | |
| 584 | #[cfg(windows)] |
| 585 | pub(crate) async fn maybe_execute_simple_windows_http_command(command: &str) -> Option<ToolOutput> { |
| 586 | let parsed = parse_simple_windows_http_command(command)?; |
| 587 | let method = reqwest::Method::from_bytes(parsed.method.as_bytes()).ok()?; |
| 588 | let client = reqwest::Client::new(); |
| 589 | let mut request = client.request(method, &parsed.url); |
| 590 | |
| 591 | for (name, value) in &parsed.headers { |
| 592 | request = request.header(name, value); |
| 593 | } |
| 594 | |
| 595 | if let Some(body) = parsed.body { |
| 596 | request = request.body(body); |
| 597 | } |
| 598 | |
| 599 | let response = match request.send().await { |
| 600 | Ok(resp) => resp, |
| 601 | Err(error) => { |
| 602 | return Some(ToolOutput::error(format!( |
| 603 | "HTTP request failed for Windows curl compatibility path: {error}" |
| 604 | ))); |
| 605 | } |
| 606 | }; |
| 607 | |
| 608 | let status = response.status(); |
| 609 | let text = match response.text().await { |
| 610 | Ok(body) => body, |
| 611 | Err(error) => { |
| 612 | return Some(ToolOutput::error(format!( |
| 613 | "HTTP response read failed for Windows curl compatibility path: {error}" |
| 614 | ))); |
| 615 | } |
| 616 | }; |
| 617 | |
| 618 | Some(ToolOutput { |
| 619 | content: if text.is_empty() { |
| 620 | String::new() |
| 621 | } else { |
| 622 | format!("{text}\n") |
| 623 | }, |
| 624 | success: status.is_success(), |
| 625 | metadata: Some(serde_json::json!({ |
| 626 | "exit_code": if status.is_success() { 0 } else { 22 }, |
| 627 | "http_status": status.as_u16(), |
| 628 | "compat_path": "windows_http_direct", |
| 629 | "json_body": parsed.json_body, |
| 630 | })), |
| 631 | images: vec![], |
| 632 | error_kind: None, |
| 633 | }) |
| 634 | } |
| 635 | |
| 636 | #[cfg(windows)] |
| 637 | fn preprocess_windows_command(command: &str) -> String { |