Skip to content

Commit 6d96dde

Browse files
committed
allow user to pass content_type to request method.
1 parent 9d75832 commit 6d96dde

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

adafruit_requests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def iter_content(self, chunk_size=1, decode_unicode=False):
146146

147147

148148
# pylint: disable=too-many-branches, too-many-statements, unused-argument, too-many-arguments, too-many-locals
149-
def request(method, url, data=None, json=None, headers=None, stream=False, timeout=1):
149+
def request(method, url, data=None, json=None, headers=None, stream=False, timeout=1, content_type=None):
150150
"""Perform an HTTP request to the given url which we will parse to determine
151151
whether to use SSL ('https://') or not. We can also send some provided 'data'
152152
or a json dictionary which we will stringify. 'headers' is optional HTTP headers
@@ -212,6 +212,8 @@ def request(method, url, data=None, json=None, headers=None, stream=False, timeo
212212
data = json_module.dumps(json)
213213
sock.send(b"Content-Type: application/json\r\n")
214214
if data:
215+
if content_type is not None:
216+
sock.send(b"Content-Type: %s\r\n" % content_type)
215217
sock.send(b"Content-Length: %d\r\n" % len(data))
216218
sock.send(b"\r\n")
217219
if data:

0 commit comments

Comments
 (0)