@@ -112,7 +112,7 @@ def _get_access_token_string(self):
112112 token_string = self ._get_access_token ()['access_token' ]
113113 return token_string
114114
115- def _do_request (self , rpath , verb = 'GET' , form_data = None ):
115+ def _do_request (self , rpath , verb = 'GET' , form_data = None , headers = None ):
116116 self ._refresh_token ()
117117 data = None
118118 if form_data is not None :
@@ -121,14 +121,24 @@ def _do_request(self, rpath, verb='GET', form_data=None):
121121
122122 LOG .info ("Request %s rpath %s" % (verb , url ))
123123
124- headers = {
124+ default_headers = {
125125 'Authorization' : 'Bearer %s' % self ._get_access_token_string (),
126126 'Content-Type' : 'application/vnd.ilandcloud.api.v0.8+json' ,
127127 'Accept' : 'application/vnd.ilandcloud.api.v0.8+json'
128128 }
129129
130+ merged_headers = default_headers .copy ()
131+
132+ if headers and isinstance (headers , dict ):
133+ for header , value in headers .items ():
134+ # don't allow overriding of our default headers
135+ if header in default_headers :
136+ LOG .warning ("Header '%s' can't be overridden" % header )
137+ else :
138+ merged_headers [header ] = value
139+
130140 request_params = {
131- 'headers' : headers ,
141+ 'headers' : merged_headers ,
132142 'verify' : self ._verify_ssl
133143 }
134144
@@ -156,59 +166,69 @@ def _do_request(self, rpath, verb='GET', form_data=None):
156166 raise ApiException (json_obj )
157167 return json_obj
158168
159- def get (self , rpath ):
169+ def get (self , rpath , headers = None ):
160170 """ Perform a GET request against the iland cloud API given its
161171 resource path.
162172
163173 `iland.Api` will refresh the access token if non valid.
164174
165175 :param rpath: the resource path as a Python builtin String object
176+ :param headers: an optional dictionary of http headers to send with \
177+ the request
166178 :raises: ApiException: API requests returns an error
167179 :raises: UnauthorizedException: credentials / grants invalids
168180 :return: a JSON Object or a list of JSON Objects.
169181 """
170- return self ._do_request (rpath )
182+ return self ._do_request (rpath , headers = headers )
171183
172- def put (self , rpath , form_data = None ):
184+ def put (self , rpath , form_data = None , headers = None ):
173185 """ Perform a PUT request against the iland cloud API given its
174186 resource path.
175187
176188 `iland.Api` will refresh the access token if non valid.
177189
178190 :param rpath: the resource path as a Python builtin String object
179191 :param form_data: a Python builtin dict object
192+ :param headers: an optional dictionary of http headers to send with \
193+ the request
180194 :raises: ApiException: API requests returns an error
181195 :raises: UnauthorizedException: credentials / grants invalids
182196 :return: a JSON Object or a list of JSON Objects.
183197 """
184- return self ._do_request (rpath , verb = 'PUT' , form_data = form_data )
198+ return self ._do_request (rpath , verb = 'PUT' , form_data = form_data ,
199+ headers = headers )
185200
186- def post (self , rpath , form_data = None ):
201+ def post (self , rpath , form_data = None , headers = None ):
187202 """ Perform a POST request against the iland cloud API given its
188203 resource path.
189204
190205 `iland.Api` will refresh the access token if non valid.
191206
192207 :param rpath: the resource path as a Python builtin String object
193208 :param form_data: a Python builtin dict object
209+ :param headers: an optional dictionary of http headers to send with \
210+ the request
194211 :raises: ApiException: API requests returns an error
195212 :raises: UnauthorizedException: credentials / grants invalids
196213 :return: a JSON Object or a list of JSON Objects.
197214 """
198- return self ._do_request (rpath , verb = 'POST' , form_data = form_data )
215+ return self ._do_request (rpath , verb = 'POST' , form_data = form_data ,
216+ headers = headers )
199217
200- def delete (self , rpath ):
218+ def delete (self , rpath , headers = None ):
201219 """ Perform a DELETE request against the iland cloud API given its
202220 resource path.
203221
204222 `iland.Api` will refresh the access token if non valid.
205223
206224 :param rpath: the resource path as a Python builtin String object
225+ :param headers: an optional dictionary of http headers to send with \
226+ the request
207227 :raises: ApiException: API requests returns an error
208228 :raises: UnauthorizedException: credentials / grants invalids
209229 :return: a JSON Object or a list of JSON Objects.
210230 """
211- return self ._do_request (rpath , verb = 'DELETE' )
231+ return self ._do_request (rpath , verb = 'DELETE' , headers = headers )
212232
213233 def get_access_token (self ):
214234 """ Returns the access token in use for this session.
0 commit comments