@@ -69,6 +69,47 @@ func (h *ClientProvider) Request(url string, method string, header map[string]st
6969 return res .StatusCode , buf .Bytes (), nil
7070}
7171
72+ // RequestWithHeaders requests http and returns headers too
73+ func (h * ClientProvider ) RequestWithHeaders (url string , method string , header map [string ]string , body []byte , params map [string ]string ) (statusCode int , resBody []byte , resHeaders map [string ][]string , err error ) {
74+ req , err := http .NewRequest (method , url , bytes .NewBuffer (body ))
75+ if err != nil {
76+ return 0 , nil , nil , err
77+ }
78+
79+ if cType , ok := header ["Content-Type" ]; ! ok || cType == "application/json" {
80+ req .Header .Add ("Content-Type" , "application/json" )
81+ delete (header , "Content-Type" )
82+ }
83+
84+ if header != nil {
85+ for k , v := range header {
86+ req .Header .Add (k , v )
87+ }
88+ }
89+
90+ if params != nil {
91+ q := req .URL .Query ()
92+ for k , v := range params {
93+ q .Add (k , v )
94+ }
95+ req .URL .RawQuery = q .Encode ()
96+ }
97+
98+ // Do request
99+ res , err := h .httpclient .Do (req )
100+ if err != nil {
101+ return 0 , nil , nil , err
102+ }
103+
104+ var buf bytes.Buffer
105+ _ , err = buf .ReadFrom (res .Body )
106+ if err != nil {
107+ return 0 , nil , nil , err
108+ }
109+
110+ return res .StatusCode , buf .Bytes (), res .Header , nil
111+ }
112+
72113// RequestCSV requests http API that returns csv result
73114func (h * ClientProvider ) RequestCSV (url string ) ([][]string , error ) {
74115 resp , err := http .Get (url )
0 commit comments