@@ -3,7 +3,8 @@ package cmd
33import (
44 "errors"
55 "fmt"
6- "io/ioutil"
6+ "io"
7+ "net/http"
78 "strings"
89
910 "github.com/ans-group/cli/internal/pkg/helper"
@@ -35,14 +36,15 @@ func rawCmd(f connection.ConnectionFactory) *cobra.Command {
3536 cmd .Flags ().String ("method" , "GET" , "Method for request" )
3637 cmd .Flags ().StringP ("request" , "X" , "GET" , "Method for request (curl alias for 'method')" )
3738 cmd .Flags ().StringP ("data" , "d" , "" , "Data for request" )
39+ cmd .Flags ().StringArrayP ("header" , "H" , []string {}, "Additional header for request" )
3840 return cmd
3941}
4042
4143type rawCommandOutput string
4244
4345func (r * rawCommandOutput ) Deserialize (resp * connection.APIResponse ) error {
4446 defer resp .Response .Body .Close ()
45- bodyBytes , err := ioutil .ReadAll (resp .Response .Body )
47+ bodyBytes , err := io .ReadAll (resp .Response .Body )
4648 if err != nil {
4749 return err
4850 }
@@ -88,6 +90,19 @@ func raw(c connection.Connection, cmd *cobra.Command, args []string) error {
8890 req .Body = & commandData
8991 }
9092
93+ if cmd .Flags ().Changed ("header" ) {
94+ req .Headers = http.Header {}
95+ headers , _ := cmd .Flags ().GetStringArray ("header" )
96+ for _ , header := range headers {
97+ headerParts := strings .SplitN (header , ":" , 2 )
98+ if len (headerParts ) != 2 {
99+ return fmt .Errorf ("invalid header format: %s" , header )
100+ }
101+
102+ req .Headers .Add (strings .TrimSpace (headerParts [0 ]), strings .TrimSpace (headerParts [1 ]))
103+ }
104+ }
105+
91106 resp , err := c .Invoke (req )
92107 if err != nil {
93108 return err
0 commit comments