(args []string)
| 25 | } |
| 26 | |
| 27 | func (cmd CurlCommand) Execute(args []string) error { |
| 28 | responseBodyBytes, httpResponse, err := cmd.Actor.MakeCurlRequest( |
| 29 | cmd.HTTPMethod, |
| 30 | cmd.RequiredArgs.Path, |
| 31 | cmd.CustomHeaders, |
| 32 | string(cmd.HTTPData), |
| 33 | cmd.FailOnHTTPError, |
| 34 | ) |
| 35 | |
| 36 | if err != nil { |
| 37 | return err |
| 38 | } |
| 39 | |
| 40 | if alreadyWroteVerboseOutput, _ := cmd.Config.Verbose(); alreadyWroteVerboseOutput { |
| 41 | return nil |
| 42 | } |
| 43 | |
| 44 | var bytesToWrite []byte |
| 45 | var headerBytes []byte |
| 46 | if cmd.IncludeResponseHeaders && httpResponse != nil { |
| 47 | headerBytes, _ = httputil.DumpResponse(httpResponse, false) |
| 48 | bytesToWrite = append(bytesToWrite, headerBytes...) |
| 49 | } |
| 50 | |
| 51 | bytesToWrite = append(bytesToWrite, responseBodyBytes...) |
| 52 | |
| 53 | if cmd.OutputFile != "" { |
| 54 | err = os.WriteFile(cmd.OutputFile.String(), bytesToWrite, 0666) |
| 55 | if err != nil { |
| 56 | return translatableerror.FileCreationError{Err: err} |
| 57 | } |
| 58 | |
| 59 | cmd.UI.DisplayOK() |
| 60 | return nil |
| 61 | } |
| 62 | |
| 63 | // Check if the response contains binary data |
| 64 | if isBinary(httpResponse, responseBodyBytes) { |
| 65 | // For binary data, write response headers with string conversion |
| 66 | // and the response body without string conversion |
| 67 | if cmd.IncludeResponseHeaders { |
| 68 | cmd.UI.DisplayTextLiteral(string(headerBytes)) |
| 69 | } |
| 70 | cmd.UI.GetOut().Write(responseBodyBytes) |
| 71 | } else { |
| 72 | cmd.UI.DisplayTextLiteral(string(bytesToWrite)) |
| 73 | } |
| 74 | |
| 75 | return nil |
| 76 | } |
| 77 | |
| 78 | // isBinary determines if the provided `data` is likely binary content. |
| 79 | // It first checks if the given `contentType` (e.g., from an HTTP header) is a known binary MIME type. |
nothing calls this directly
no test coverage detected