• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

AndreLouisCaron/httpxx: C++ wrapper for C-based HTTP parser

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

AndreLouisCaron/httpxx

开源软件地址:

https://github.com/AndreLouisCaron/httpxx

开源编程语言:

C++ 90.0%

开源软件介绍:

httpxx --- HTTP Parser for C++

Authors: André Caron
Contact: [email protected]
Version: 0.1
Date: 2011-07-18

Description

This library is a simple C++ wrapper for the C library http-parser [1] (This code was derived from the HTTP parser code in NGINX). http-parser is a simple HTTP streaming parser (for those of you familiar with XML, it works much like a SAX parser). It knows nothing of sockets or streams. You feed it data and it invokes registered callbacks to notify of available data. Because http-parser operates at the very lowest level, it does not buffer data or allocate memory dynamically. This library attempts to make that library easily usable by C++ programs by interpreting those callbacks and buffering data where needed.

[1]https://github.com/ry/http-parser.

Documentation

The API for defined classes is documented using Doxygen [2]. You will need to run Doxygen from the project source folder to generate the output HTML.

[2]http://www.stack.nl/~dimitri/doxygen/

Compiled HTML documentation for official releases is available online. Check the project page.

Fetching the code

This project does not distribute the code to http-parser directly. To fetch the entire source code, make sure you fetch submodules [3] too:

$ git clone ...
$ cd httpxx
$ git submodule init
$ git submodule update
[3]http://book.git-scm.com/5_submodules.html

Portability

http-parser itself has no dependencies and compiles with C++ compilers. httpcxx uses only standard library facilities (namely std::string and std::map) and introduces no additional dependencies.

The code should compile as is under a standard-compliant C++03 implementation.

Memory allocation policy

A good memory allocation policy is important in server programs, which typically run for a long time and suffer from memory fragmentation. httpcxx does its best to avoid repeated allocation, but it needs a little help on your part.

http::Request and http::Response parser object allocate memory as required because they buffer different parts of the incoming HTTP request/response in std::string instances. However, they are implemented carefully as to use the growing property of std::string [4] to their advantage. In particular, you may re-use http::Request and http::Response parser objects for parsing multiple request/response objects using their .clear() method. This method marks all header lengths as 0 but keeps the instances as well as the map. All this ensures that parsers avoid repeated memory allocation.

[4]std::string instances keep the allocated memory buffer even when you resize them such that their length decreases. In particular, std::string::clear() marks the string length as 0 but keeps the allocated buffer.

Samples / demos

Check out the sample programs in the demo/ subfolder.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap