| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
10年前发布

HTTP 协议解析库:fast-http

这是一个快速的 HTTP request/response 协议解析器,用于 Common Lisp开发中。 大部分移植自 C 语言版本的 http-parser.

具体有多快请看下图:

HTTP 协议解析库:fast-http

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 and http-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 for make-parser and make-multipart-parser doesn't take a flag body-complete-p.
    • Use finish-callback to know if the parsing is finished.
  • :multipart-callback of make-parser and :callback of make-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.
  • Doesn't use a property list as a representation of HTTP headers. (See issue #1)

项目主页:http://www.open-open.com/lib/view/home/1414720724559

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1414720724559.html
fast-http Lisp开发