@@ -76,27 +76,32 @@ func (c *Client) PostFormWithHeaders(url string, data url.Values) (*http.Respons
7676 return nil , fmt .Errorf ("Error preparing request: %s" , err )
7777 }
7878
79- SetHeaders (c , req , contentTypeApplicationUrlEncoded )
79+ SetHeaders (c , req , contentTypeApplicationUrlEncoded , nil )
8080 return c .httpClient .Do (req )
8181}
8282
83- func (c * Client ) DoJsonRequestWithHeaders (method string , url string , data []byte ) (* http.Response , error ) {
83+ func (c * Client ) DoJsonRequestWithCustomHeaders (method string , url string , data []byte , headers map [ string ] string ) (* http.Response , error ) {
8484 req , err := PrepareJsonRequest (method , url , data )
8585 if err != nil {
8686 return nil , fmt .Errorf ("Error preparing request: %s" , err )
8787 }
8888
89- SetHeaders (c , req , contentTypeApplicationJson )
89+ SetHeaders (c , req , contentTypeApplicationJson , headers )
90+
9091 return c .httpClient .Do (req )
9192}
9293
94+ func (c * Client ) DoJsonRequestWithHeaders (method string , url string , data []byte ) (* http.Response , error ) {
95+ return c .DoJsonRequestWithCustomHeaders (method , url , data , nil )
96+ }
97+
9398func (c * Client ) DoJsonRequestWithHeadersForm (method string , url string , data []byte , contentType string ) (* http.Response , error ) {
9499 req , err := PrepareJsonRequest (method , url , data )
95100 if err != nil {
96101 return nil , fmt .Errorf ("Error preparing request: %s" , err )
97102 }
98103
99- SetHeaders (c , req , contentType )
104+ SetHeaders (c , req , contentType , nil )
100105 return c .httpClient .Do (req )
101106}
102107
@@ -108,9 +113,16 @@ func PrepareJsonRequest(method string, url string, data []byte) (*http.Request,
108113 return http .NewRequest (method , url , bytes .NewReader (data ))
109114}
110115
111- func SetHeaders (c * Client , req * http.Request , contentType string ) {
116+ func SetHeaders (c * Client , req * http.Request , contentType string , customHeaders map [ string ] string ) {
112117 req .Header .Set ("Content-Type" , contentType )
113118 req .Header .Set ("x-api-id" , c .config .APIID )
114119 req .Header .Set ("x-api-key" , c .config .APIKey )
115120 req .Header .Set ("x-tf-provider-ver" , c .providerVersion )
121+
122+ if customHeaders != nil {
123+ for name , value := range customHeaders {
124+ req .Header .Set (name , value )
125+ }
126+ }
127+
116128}
0 commit comments