MCPcopy Index your code
hub / github.com/AI45Lab/Code / parse_simple_windows_http_command

Function parse_simple_windows_http_command

core/src/tools/builtin/bash.rs:494–582  ·  view source on GitHub ↗
(command: &str)

Source from the content-addressed store, hash-verified

492
493#[cfg(windows)]
494fn parse_simple_windows_http_command(command: &str) -> Option<SimpleWindowsHttpCommand> {
495 if contains_shell_control_operators(command) {
496 return None;
497 }
498
499 let tokens = tokenize_windows_command(command)?;
500 let first = tokens.first()?.to_ascii_lowercase();
501 if !matches!(first.as_str(), "curl" | "curl.exe" | "wget" | "wget.exe") {
502 return None;
503 }
504
505 let mut method: Option<String> = None;
506 let mut url: Option<String> = None;
507 let mut headers = Vec::new();
508 let mut body: Option<String> = None;
509 let mut json_body = false;
510 let mut i = 1usize;
511
512 while i < tokens.len() {
513 match tokens[i].as_str() {
514 "-s" | "-S" | "-sS" | "--silent" | "--show-error" | "-L" | "--location" => {
515 i += 1;
516 }
517 "-X" | "--request" => {
518 method = Some(tokens.get(i + 1)?.to_string());
519 i += 2;
520 }
521 "-H" | "--header" => {
522 let header = tokens.get(i + 1)?.to_string();
523 let (name, value) = header.split_once(':')?;
524 headers.push((name.trim().to_string(), value.trim().to_string()));
525 i += 2;
526 }
527 "-d" | "--data" | "--data-raw" | "--data-binary" => {
528 body = Some(tokens.get(i + 1)?.to_string());
529 i += 2;
530 }
531 "--json" => {
532 body = Some(tokens.get(i + 1)?.to_string());
533 json_body = true;
534 i += 2;
535 }
536 token if token.starts_with("http://") || token.starts_with("https://") => {
537 url = Some(token.to_string());
538 i += 1;
539 }
540 token if token.starts_with('-') => return None,
541 token => {
542 if url.is_none() && (token.starts_with("http://") || token.starts_with("https://"))
543 {
544 url = Some(token.to_string());
545 i += 1;
546 } else {
547 return None;
548 }
549 }
550 }
551 }

Calls 6

tokenize_windows_commandFunction · 0.85
lenMethod · 0.45
as_strMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected