Skip to content

Commit 96bd01e

Browse files
dotdashnotdotsoftwaredpgeorge
authored andcommitted
urllib.urequest: Add support for headers to urequest.urlopen.
This is an extension to CPython, similar to the `method` argument. Signed-off-by: Adam Lewis <[email protected]>
1 parent 567540d commit 96bd01e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

micropython/urllib.urequest/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
metadata(version="0.7.0")
1+
metadata(version="0.8.0")
22

33
# Originally written by Paul Sokolovsky.
44

micropython/urllib.urequest/urllib/urequest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import socket
22

33

4-
def urlopen(url, data=None, method="GET"):
4+
def urlopen(url, data=None, method="GET", headers={}):
55
if data is not None and method == "GET":
66
method = "POST"
77
try:
@@ -40,6 +40,12 @@ def urlopen(url, data=None, method="GET"):
4040
s.write(host)
4141
s.write(b"\r\n")
4242

43+
for k in headers:
44+
s.write(k)
45+
s.write(b": ")
46+
s.write(headers[k])
47+
s.write(b"\r\n")
48+
4349
if data:
4450
s.write(b"Content-Length: ")
4551
s.write(str(len(data)))

0 commit comments

Comments
 (0)