feat: support for self-signed ssl and bugfixes (#3)

This commit is contained in:
Victor Westerlund 2023-06-05 14:18:03 +02:00 committed by GitHub
parent 13e7e5301a
commit 1a07c60448
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

1
.gitignore vendored
View file

@ -15,6 +15,7 @@ Homestead.yaml
npm-debug.log
yarn-error.log
public/robots.txt
__pycache__
# OS generated files #
######################

View file

@ -47,7 +47,9 @@ class Client:
# Close socket connection when class instance removed
def __del__(self):
self._socket.close()
# Close socket if connected
if (self._con == Connection.AF_UNIX):
self._socket.close()
# Resolve connection type from endpoint string.
# If the string is a valid URL we will treat it as HTTP otherwise we will assume it's a path on disk to a UNIX socket file.
@ -75,9 +77,9 @@ class Client:
# Remove leading "/" if present, as it's already present in self._endpoint
endpoint = endpoint if endpoint[-1] != "/" else endpoint[:-1]
resp = requests.request(method.name, self._endpoint + endpoint, headers=self.http_headers(), data=json.dumps(payload))
# Return response as tuple of response code and response body as plain text
return (resp.status_code, resp.text)
resp = requests.request(method.name, self._endpoint + endpoint, verify=self._https_peer_verify, headers=self.http_headers(), data=json.dumps(payload))
# Return response as tuple of response code and response body as decoded JSON (mixed)
return (resp.status_code, json.loads(resp.text))
def socket_txn(self, endpoint: str, method: Union[Method, str] = None, payload: list = None) -> tuple:
data = f'["{endpoint}","{method.name}","{json.dumps(payload)}"]'