HTTP 协议解析库:fast-http
这是一个快速的 HTTP request/response 协议解析器,用于 Common Lisp开发中。 大部分移植自 C 语言版本的 http-parser.
具体有多快请看下图:
-
http-parser: An HTTP Parser for Node.js
NOTE: Deleted PicoHTTPParser because the benchmark was wrong. It's 3.7 times faster than fast-http. Amazing.
详情请看 Benchmark
用法
其API非常类似于 http-parse.
(let* ((http (make-http-request)) (parser (make-parser http :header-callback (lambda (headers) (my-app:got-headers!!! headers)) :body-callback (lambda (bytes) (my-app:got-body-piece bytes))))) (loop for http-data = (my-app:get-http-data-from-request-i-sent-out-earlier) do (multiple-value-bind (http headers-finished-p body-finished-p) (funcall parser http-data) (when body-finished-p (my-app:close-http-stream)) ...)))
API 与 http-parse 不同之处
http
,http-request
andhttp-response
are structure classes, not standard classes.http
doesn't have:force-stream
option. (always streaming)http
doesn't have:store-body
option because it can consume much memory.body-callback
formake-parser
andmake-multipart-parser
doesn't take a flagbody-complete-p
.- Use
finish-callback
to know if the parsing is finished.
- Use
:multipart-callback
ofmake-parser
and:callback
ofmake-multipart-parser
takes a stream, not a body octet vector at the 4th argument.- Raises errors aggressively while parsing.
- Handle
fast-http-error
as you needed.
- Handle
- Doesn't use a property list as a representation of HTTP headers. (See issue #1)
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!