Skip to content

Commit acf98ad

Browse files
Gadgetoiddpgeorge
authored andcommitted
requests: Add context manager for response object.
When accessing response.raw it's not always obvious you should call `response.close()` to close and free the socket. Since lwIP can have a socket limit this can very quickly result in cryptic ENOMEM errors. This matches the official requests which has the same context manager on `Response` objects. Signed-off-by: Phil Howard <github@gadgetoid.com>
1 parent 4ac5958 commit acf98ad

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

python-ecosys/requests/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
metadata(version="0.10.2", pypi="requests")
1+
metadata(version="0.11.0", pypi="requests")
22

33
package("requests")

python-ecosys/requests/requests/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def json(self):
3232

3333
return json.loads(self.content)
3434

35+
def __enter__(self):
36+
return self
37+
38+
def __exit__(self, exc_type, exc_val, exc_tb):
39+
self.close()
40+
3541

3642
def request(
3743
method,

0 commit comments

Comments
 (0)