MCPcopy Create free account
hub / github.com/boy-hack/hack-requests / http

Method http

HackRequests/HackRequests.py:250–337  ·  view source on GitHub ↗
(self, url, **kwargs)

Source from the content-addressed store, hash-verified

248 return response(rep, _url, log, )
249
250 def http(self, url, **kwargs):
251 method = kwargs.get("method", "GET")
252 post = kwargs.get("post", None) or kwargs.get("data", None)
253 location = kwargs.get('location', True)
254 locationcount = kwargs.get("locationcount", 0)
255
256 proxy = kwargs.get('proxy', None)
257 headers = kwargs.get('headers', {})
258
259 # real host:ip
260 real_host = kwargs.get("real_host", None)
261
262 if isinstance(headers, str):
263 headers = extract_dict(headers.strip(), '\n', ': ')
264 cookie = kwargs.get("cookie", None)
265 if cookie:
266 cookiestr = cookie
267 if isinstance(cookie, dict):
268 cookiestr = ""
269 for k, v in cookie.items():
270 cookiestr += "{}={}; ".format(k, v)
271 cookiestr = cookiestr.strip("; ")
272 headers["Cookie"] = cookiestr
273 for arg_key, h in [
274 ('referer', 'Referer'),
275 ('user_agent', 'User-Agent'), ]:
276 if kwargs.get(arg_key):
277 headers[h] = kwargs.get(arg_key)
278 if "Content-Length" in headers:
279 del headers["Content-Length"]
280
281 urlinfo = scheme, host, port, path = self._get_urlinfo(url, real_host)
282 log = {}
283 try:
284 conn = self.httpcon.get_con(urlinfo, proxy=proxy)
285 except:
286 raise
287 conn._send_output = self._send_output(conn._send_output, conn, log)
288 tmp_headers = copy.deepcopy(headers)
289 if post:
290 method = "POST"
291 if isinstance(post, str):
292 try:
293 post = extract_dict(post, sep="&")
294 except:
295 pass
296 try:
297 post = parse.urlencode(post)
298 except:
299 pass
300 tmp_headers["Content-Type"] = kwargs.get(
301 "Content-type", "application/x-www-form-urlencoded")
302 tmp_headers["Accept"] = tmp_headers.get("Accept", "*/*")
303 tmp_headers['Accept-Encoding'] = tmp_headers.get("Accept-Encoding", "gzip, deflate")
304 tmp_headers['Connection'] = 'close'
305 tmp_headers['User-Agent'] = tmp_headers['User-Agent'] if tmp_headers.get(
306 'User-Agent') else 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36'
307

Callers

nothing calls this directly

Calls 6

_get_urlinfoMethod · 0.95
_send_outputMethod · 0.95
extract_dictFunction · 0.85
HackErrorClass · 0.85
responseClass · 0.85
get_conMethod · 0.80

Tested by

no test coverage detected