在python 3 asyncio上使用hyper-h2实现http/2。

aioh2的Python项目详细描述


空气2

https://img.shields.io/pypi/v/aioh2.svghttps://img.shields.io/travis/decentfox/aioh2.svgDocumentation Status

在python 3异步上使用hyper-h2实现http/2。

功能

  • 异步http/2客户端和服务器
  • 数据流与托管流和优先级控制< /LI>
  • 可选无痒健康检查
  • 更多信息

非功能:

  • 请求/响应包装器
  • Web服务器、调度器、cookie等
  • http/2升级

示例

一个打招呼的服务器:

# Server request handlerasyncdefon_connected(proto):try:whileTrue:# Receive a request from queuestream_id,headers=awaitproto.recv_request()# Send response headersawaitproto.start_response(stream_id,{':status':'200'})# Response body starts with "hello"awaitproto.send_data(stream_id,b'hello, ')# Read all request body as a name from client sidename=awaitproto.read_stream(stream_id,-1)# Amend response body with the nameawaitproto.send_data(stream_id,name)# Send trailers with the length of the nameawaitproto.send_trailers(stream_id,{'len':str(len(name))})exceptasyncio.CancelledError:# do cleanup herepass# Start server on random port, with maximum concurrent requests of 3server=awaitaioh2.start_server(on_connected,port=0,concurrency=3)port=server.sockets[0].getsockname()[1]

还有一个客户要试用:

# Open client connectionclient=awaitaioh2.open_connection('0.0.0.0',port,functional_timeout=0.1)# Optionally wait for an ack of tickless ping - a.k.a. until functionalawaitasyncio.sleep(0.1)# simulate client being busy with something elsertt=awaitclient.wait_functional()ifrtt:print('Round-trip time: %.1fms'%(rtt*1000))# Start request with headersstream_id=awaitclient.start_request({':method':'GET',':path':'/index.html'})# Send my name "world" as whole request bodyawaitclient.send_data(stream_id,b'world',end_stream=True)# Receive response headersheaders=awaitclient.recv_response(stream_id)print('Response headers:',headers)# Read all response bodyresp=awaitclient.read_stream(stream_id,-1)print('Response body:',resp)# Read response trailerstrailers=awaitclient.recv_trailers(stream_id)print('Response trailers:',trailers)client.close_connection()awaitasyncio.sleep(.1)

上面的例子可以在examples/core.py找到。

学分

非常感谢来自Cory Benfield的伟大图书馆hyper-h2

DecentFoX Studio是一家提供高质量服务的软件外包公司 为全球客户提供基于网络的产品和移动应用,采用敏捷方法, 专注于前沿技术和快速开发的可扩展架构。

这个包是用Cookiecutteraudreyr/cookiecutter-pypackage项目模板创建的。

历史记录

0.2.1(2017-12-03)

  • 更新至H23.0(由Arthur Darcet和Peter Wu提供)
  • 放弃了对Python3.3的支持

0.1.0(2016-2-6)

  • pypi上的第一个版本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java什么是RuleContext类实现中的invokingState?   如何将Scala Seq传递给Java varargs   ELK在ubuntu上升级到最新版本后仍提示升级java版本   java如何实现服务器关闭   类型为java的0上的安卓。无法将lang.String转换为JSONArray   java如何在通过Selenium登录时避免验证代码?   java同时下载文件并上传到别处(转发文件)   java jodatime 1.6.2 jar未从maven central repository下载   java OpenGL ES 2.0屏幕滚动:translate vs.setLookatM   安卓 Java如何在另一个类中使用活动方法   java CSVFormat。RFC4180忽略中引用的值。csv文件   从电话号码中分离数字的java   java找不到net。来源:福格。jtds。jdbc。Tomcat web应用程序中的驱动程序   java Red5无法解析bean引用   java忽略日志配置