Skip to content

Commit 4c4a743

Browse files
author
Paul Sokolovsky
committed
asyncio: Add basic asyncio stream interface test.
1 parent 2caed7d commit 4c4a743

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

asyncio/test_http_client.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import asyncio
2+
3+
@asyncio.coroutine
4+
def print_http_headers(url):
5+
reader, writer = yield from asyncio.open_connection(url, 80)
6+
print(reader, writer)
7+
print("================")
8+
query = "GET / HTTP/1.0\r\n\r\n"
9+
yield from writer.write(query.encode('latin-1'))
10+
while True:
11+
line = yield from reader.readline()
12+
if not line:
13+
break
14+
if line:
15+
print(line.rstrip())
16+
17+
import logging
18+
logging.basicConfig(level=logging.INFO)
19+
url = "google.com"
20+
loop = asyncio.get_event_loop()
21+
#task = asyncio.async(print_http_headers(url))
22+
#loop.run_until_complete(task)
23+
loop.call_soon(print_http_headers(url))
24+
loop.run_forever()
25+
loop.close()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy