In the parsers documentation, let's get to the point where we can demo how to wire up the NetworkBackend and HTTPParser together to create simple one-shot connection requests...
def request(method: str, url: str) -> tuple(int, bytes):
b = httpx.NetworkBackend()
u = httpx.URL(url)
secure = {"https": True, "http": False}[u.scheme]
with b.connect(u.host, u.port, secure=secure) as stream:
p = httpx.HTTPParser(stream, mode='CLIENT')
p.send_method_line(method, u.target, "HTTP/1.1")
p.send_headers([("Host", u.netloc), ("Connection", "close")])
p.send_body("")
protocol, status, reason = p.recv_status_line()
headers = p.recv_headers()
s = httpx.HTTPStream(p)
body = s.read()
return status, body
status, body = request("GET", "https://www.example.com")
Some points still todo here...
- Neaten up API. for
.connect() on NetworkBackend. (eg. secure by default.)
HTTPStream to accept parser instance. Document this class in the Parser docs.
- Review bytes/str above.
In the parsers documentation, let's get to the point where we can demo how to wire up the
NetworkBackendandHTTPParsertogether to create simple one-shot connection requests...Some points still todo here...
.connect()onNetworkBackend. (eg. secure by default.)HTTPStreamto accept parser instance. Document this class in the Parser docs.