HTTP/1.1, protocol design, pySpeedtest client

本文分享了作者两次编写HTTP/1.1客户端协议解析代码的经历,从简单文本协议到复杂规范的发展历程,指出了协议定义中存在的问题,并提出用状态机语言替代文本定义的理想。同时介绍了其中一个实现——Python Speedtest.net客户端,它提供类似网页版的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

So recently I've been writing HTTP/1.1 client side protocol parsing stuff. Twice.

When I went through RFC2616, even shallow like I was doing (merely picking bits that I need to know to get my stuff working),  I get the feeling of seeing through time. I saw where the protocol came from a simple, lined text based conversation protocol, with later session boundaries added (Content-Length), then connection control (Connection: keep-alive), then multiple responses with Transfer-Encoding: chunked (thankfully I didn't have to deal with multipart/form-data yet).

And only this time, SIMPLE doesn't necessarily mean "BEAUTIFUL". I saw ugly bits like "hex-coded, text based" chunk sizes, saw "1*DIGIT '/' 1*DIGIT" version number "e.g. HTTP/2.13", saw all the unspecification of behaviors.

I used to think that protocol definitions should not be in text but rather a state-machine of some language, preferably parsable, can be verified and interacted. Sometime I may pick up this idea later.

Anyway. One of the two (!) implementations I mentioned at the beginning, the Python Speedtest.net client, has been put on GitHub. Built upon asyncore, it provides similar tests you could take only with the Flash based test on their web. Credits goes to all the generous authors who released their sample code on the web, with credits in README.md.
Link: https://github.com/wolf0403/pySpeedtest 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值