Skip to content

Commit 3b639b6

Browse files
authored
Merge pull request #97 from JohnDoe117/master
Add the `destroySession` method and support the `with` syntax.
2 parents f8938eb + 075f6bb commit 3b639b6

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

tls_client/cffi.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@
2626

2727
freeMemory = library.freeMemory
2828
freeMemory.argtypes = [ctypes.c_char_p]
29-
freeMemory.restype = ctypes.c_char_p
29+
freeMemory.restype = ctypes.c_char_p
30+
31+
destroySession = library.destroySession
32+
destroySession.argtypes = [ctypes.c_char_p]
33+
destroySession.restype = ctypes.c_char_p
9.24 MB
Binary file not shown.
9.78 MB
Binary file not shown.
10 MB
Binary file not shown.

tls_client/sessions.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .cffi import request, freeMemory
1+
from .cffi import request, freeMemory, destroySession
22
from .cookies import cookiejar_from_dict, get_cookie_header, merge_cookies, extract_cookies_to_jar
33
from .exceptions import TLSClientExeption
44
from .response import build_response
@@ -271,6 +271,31 @@ def __init__(
271271
# debugging
272272
self.debug = debug
273273

274+
def __enter__(self):
275+
return self
276+
277+
def __exit__(self, *args):
278+
self.close()
279+
280+
def close(self):
281+
destroySessionPayload = {
282+
"sessionId": self._session_id
283+
}
284+
285+
destroySessionResponse = destroySession(dumps(destroySessionPayload).encode('utf-8'))
286+
# we dereference the pointer to a byte array
287+
destroySessionResponse_bytes = ctypes.string_at(destroySessionResponse)
288+
# convert our byte array to a string (tls client returns json)
289+
destroySessionResponse_string = destroySessionResponse_bytes.decode('utf-8')
290+
# convert response string to json
291+
destroySessionResponse_object = loads(destroySessionResponse_string)
292+
293+
# print out output
294+
# print(destroySessionResponse_object)
295+
freeMemory(destroySessionResponse_object['id'].encode('utf-8'))
296+
297+
return destroySessionResponse_string
298+
274299
def execute_request(
275300
self,
276301
method: str,

0 commit comments

Comments
 (0)