Skip to content

Commit

Permalink
curl: override any "-w" options that might exist
Browse files Browse the repository at this point in the history
See the code comment for an explanation.
  • Loading branch information
kevinburkesegment committed Apr 20, 2022
1 parent e8701a2 commit 2280dbb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ func main() {
}

func run(ctx context.Context) error {
cArgs := make([]string, 0)
cArgs := []string{
"--header", "User-Agent: kubectl-curl",
}
flags.ParseAll(os.Args[1:], func(flag *pflag.Flag, value string) error {
if flag.Name == "silent" {
return nil // --silent is added later to all curl arguments so don't add here
Expand Down Expand Up @@ -239,7 +241,7 @@ func run(ctx context.Context) error {
}
}()

log.Printf("waiting for port fowarding to be established")
log.Printf("waiting for port forwarding to be established")
select {
case <-f.Ready:
case <-ctx.Done():
Expand All @@ -253,6 +255,11 @@ func run(ctx context.Context) error {
// print the dynamic progress view for the scenarios in which this
// plugin is useful for.
cArgs = append(cArgs, "--silent")
// Override any settings that users might have by default - for example,
// Kevin Burke has "-w \n" in his .curlrc file. Adding a new line to the end
// of the file is great for readability for most responses but breaks pprof
// and trace parsing.
cArgs = append(cArgs, "-w", "")

cmd := exec.CommandContext(ctx, "curl", cArgs...)
cmd.Stdin = os.Stdin
Expand Down

0 comments on commit 2280dbb

Please sign in to comment.