Skip to content

Commit

Permalink
Merge pull request #1094 from mwhudson/lp-1946656
Browse files Browse the repository at this point in the history
close the session object after each request to the snapd API
  • Loading branch information
dbungert authored Oct 12, 2021
2 parents b4fce71 + 7cfc7d1 commit 363098d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions subiquitycore/snapd.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,20 @@ class SnapdConnection:
def __init__(self, root, sock):
self.root = root
self.url_base = "http+unix://{}/".format(quote_plus(sock))
self.session = requests_unixsocket.Session()

def get(self, path, **args):
if args:
path += '?' + urlencode(args)
return self.session.get(self.url_base + path, timeout=60)
with requests_unixsocket.Session() as session:
return session.get(self.url_base + path, timeout=60)

def post(self, path, body, **args):
if args:
path += '?' + urlencode(args)
return self.session.post(
self.url_base + path, data=json.dumps(body),
timeout=60)
with requests_unixsocket.Session() as session:
return session.post(
self.url_base + path, data=json.dumps(body),
timeout=60)

def configure_proxy(self, proxy):
log.debug("restarting snapd to pick up proxy config")
Expand Down

0 comments on commit 363098d

Please sign in to comment.