MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / request

Method request

python/downloadprovider.py:192–242  ·  view source on GitHub ↗
(self, method, url, headers=None, data=None, json=None)

Source from the content-addressed store, hash-verified

190 return (result, self._response)
191
192 def request(self, method, url, headers=None, data=None, json=None):
193 if headers is None:
194 headers = {}
195 if data is None and json is None:
196 data = b''
197 elif data is None and json is not None:
198 data = to_bytes(dumps(json))
199 if "Content-Type" not in headers:
200 headers["Content-Type"] = "application/json"
201 elif data is not None and json is None:
202 if type(data) == dict:
203 # Urlencode data as a form body
204 data = to_bytes(urlencode(data))
205 if "Content-Type" not in headers:
206 headers["Content-Type"] = "application/x-www-form-urlencoded"
207 else:
208 assert (type(data) == bytes)
209
210 self._data = data
211 if len(data) > 0 and "Content-Length" not in headers:
212 headers["Content-Length"] = len(data)
213 if "Content-Type" not in headers:
214 headers["Content-Type"] = "application/octet-stream"
215
216 callbacks = core.BNDownloadInstanceInputOutputCallbacks()
217 callbacks.readCallback = callbacks.readCallback.__class__(self._read_callback)
218 callbacks.writeCallback = callbacks.writeCallback.__class__(self._write_callback)
219 callbacks.readContext = 0
220 callbacks.writeContext = 0
221 callbacks.progressContext = 0
222 self._response = b""
223 header_keys = (ctypes.c_char_p * len(headers))()
224 header_values = (ctypes.c_char_p * len(headers))()
225 for (i, item) in enumerate(headers.items()):
226 key, value = item
227 header_keys[i] = to_bytes(key)
228 header_values[i] = to_bytes(value)
229
230 response = ctypes.POINTER(core.BNDownloadInstanceResponse)()
231 result = core.BNPerformCustomRequest(
232 self.handle, method, url, len(headers), header_keys, header_values, response, callbacks
233 )
234
235 if result != 0:
236 return None
237
238 response_headers = {}
239 for i in range(response.contents.headerCount):
240 response_headers[response.contents.headerKeys[i]] = response.contents.headerValues[i]
241
242 return DownloadInstance.Response(response.contents.statusCode, response_headers, self._response)
243
244 def get(self, url, headers=None):
245 return self.request("GET", url, headers)

Callers 4

getMethod · 0.95
postMethod · 0.95
putMethod · 0.95

Calls 2

to_bytesFunction · 0.70
itemsMethod · 0.45

Tested by

no test coverage detected