-
Notifications
You must be signed in to change notification settings - Fork 0
/
tls.py
66 lines (50 loc) · 1.77 KB
/
tls.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import requests as rq
import os
TLSCLIENT = f"http://{os.environ['GATEWAY']}:8082"
def addParamsToHeader(url, headers, proxies):
"""
Add the url and the proxy to the headers to let the tlsclient use them
"""
if proxies != {}:
headers["Poptls-Proxy"] = proxies["http"]
headers["Poptls-Url"] = url
return headers
def parseCookies(res, url):
"""
Parse the cookies from the headers into the cookiejar of the response
"""
res.cookies.clear()
sescookies = res.headers["session-cookies"].split('; ')
for x in range(len(sescookies)):
if sescookies[x] == "":
continue
domain = url.split('://')[1]
if '/' in domain:
domain = domain.split('/')[0]
res.cookies.set(sescookies[x].split('=')[0], sescookies[x].split('=')[1], domain=domain)
del res.headers["session-cookies"]
return res
def get(url, headers={}, proxies={}, timeout=10, **kargs):
"""
get request wrapper
"""
headers = addParamsToHeader(url=url, headers=headers, proxies=proxies)
res = rq.get(TLSCLIENT, headers=headers, timeout=timeout, **kargs)
res = parseCookies(res, url)
return res
def post(url, headers={}, proxies={}, timeout=10, **kargs):
"""
post request wrapper
"""
headers = addParamsToHeader(url=url, headers=headers, proxies=proxies)
res = rq.post(TLSCLIENT, headers=headers, timeout=timeout, **kargs)
res = parseCookies(res, url)
return res
def head(url, headers={}, proxies={}, timeout=10, **kargs):
"""
head request wrapper
"""
headers = addParamsToHeader(url=url, headers=headers, proxies=proxies)
res = rq.head(TLSCLIENT, headers=headers, timeout=timeout, **kargs)
res = parseCookies(res, url)
return res