| 532 | } |
| 533 | |
| 534 | func buildCurlCommand(method, uri string, headers []header, body string, redirect bool, proxy *url.URL) string { |
| 535 | var parts []string |
| 536 | parts = append(parts, "curl", "-i", "-sS", "-k") |
| 537 | if redirect { |
| 538 | parts = append(parts, "-L") |
| 539 | } |
| 540 | if method != "" && method != "GET" { |
| 541 | parts = append(parts, "-X", shellQuote(method)) |
| 542 | } |
| 543 | if proxy != nil && proxy.String() != "" { |
| 544 | parts = append(parts, "-x", shellQuote(proxy.String())) |
| 545 | } |
| 546 | for _, h := range headers { |
| 547 | parts = append(parts, "-H", shellQuote(h.key+": "+h.value)) |
| 548 | } |
| 549 | if body != "" { |
| 550 | parts = append(parts, "--data", shellQuote(body)) |
| 551 | } |
| 552 | parts = append(parts, shellQuote(uri)) |
| 553 | return strings.Join(parts, " ") |
| 554 | } |
| 555 | |
| 556 | func shellQuote(s string) string { |
| 557 | return "'" + strings.ReplaceAll(s, "'", `'"'"'`) + "'" |