Skip to content

Initial implementation - #11

Merged
lovelydinosaur merged 6 commits into
masterfrom
initial-implementation
Feb 6, 2020
Merged

Initial implementation#11
lovelydinosaur merged 6 commits into
masterfrom
initial-implementation

Conversation

@lovelydinosaur

Copy link
Copy Markdown
Contributor

A very basic initial implementation to get all the sync/async and type checking etc up and going.

Creates an HTTP/1.1 connection on every request.

Sync:

importhttpcoredefmain():
withhttpcore.SyncConnectionPool() ashttp:
http_version, status_code, reason_phrase, headers, stream=http.request(
method=b'GET',
url=(b'https', b'example.org', 443, b'/'),
headers=[(b'host', b'example.org')]
)
try:
body=b''forchunkinstream:
body+=chunkfinally:
stream.close()
print(b"%s %d %s"% (http_version, status_code, reason_phrase))
forkey, valueinheaders:
print(b"%s: %s"% (key, value))
print(b"")
print(body)
main()

Async, Trio:

importtrioimporthttpcoreasyncdefmain():
asyncwithhttpcore.AsyncConnectionPool() ashttp:
http_version, status_code, reason_phrase, headers, stream=awaithttp.request(
method=b'GET',
url=(b'https', b'example.org', 443, b'/'),
headers=[(b'host', b'example.org')]
)
try:
body=b''asyncforchunkinstream:
body+=chunkfinally:
awaitstream.close()
print(b"%s %d %s"% (http_version, status_code, reason_phrase))
forkey, valueinheaders:
print(b"%s: %s"% (key, value))
print(b"")
print(body)
trio.run(main)

Async, Asyncio:

importasyncioimporthttpcoreasyncdefmain():
asyncwithhttpcore.AsyncConnectionPool() ashttp:
http_version, status_code, reason_phrase, headers, stream=awaithttp.request(
method=b'GET',
url=(b'https', b'example.org', 443, b'/'),
headers=[(b'host', b'example.org')]
)
try:
body=b''asyncforchunkinstream:
body+=chunkfinally:
awaitstream.close()
print(b"%s %d %s"% (http_version, status_code, reason_phrase))
forkey, valueinheaders:
print(b"%s: %s"% (key, value))
print(b"")
print(body)
asyncio.run(main())

@lovelydinosaur
lovelydinosaur merged commit a24431c into masterFeb 6, 2020
@lovelydinosaur
lovelydinosaur deleted the initial-implementation branch February 6, 2020 11:40
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@lovelydinosaur