Code Monkey home page Code Monkey logo

http-client's Introduction

C/C++ CI issues forks stars license

    __     __   __                       __ _               __ 
   / /_   / /_ / /_ ____          _____ / /(♥)___   ____   / /_
  / __ \ / __// __// __ \ ______ / ___// // // _ \ / __ \ / __/
 / / / // /_ / /_ / /_/ //_____// /__ / // //  __// / / // /_  
/_/ /_/ \__/ \__// .___/        \___//_//_/ \___//_/ /_/ \__/  
                /_/                                                                   

http-client

本项目是一个高稳定性与高性能的 HTTP 客户端,可在多平台使用,拥有极简的 API 接口。

整体架构如下:

http-client架构

解析一下整个架构:

  • 最上方是对外的 API 接口。

  • 接着就是 client 管理器,通过池化技术实现了 client pool,在使用的时候从池中取出 client,用完就放回,用户基本不需要直接接触 client 实例,实现了基本的 HTTP 方法,如 GET/POST 等,还实现了 url 解析器,解析用户传入的 url,生成合适的参数递交给拦截器。

  • 实现工作队列,进行异步处理,在 CPU 支持多核的情况下,根据 CPU 的最大支持线程数量创建多个线程处理,将所有来自上层的请求按顺序放入工作队列,并行处理。

  • intercept 是拦截器,比如实现 HTTP请求HTTP应答 等,它需要依赖 HTTP 报文的处理。拦截器的主要的处理工作是通过上层传入的参数去设置网络信息(host、port 等),与服务器建立连接、重连,发起 HTTP 请求、解析来自服务器的响应报文,自动处理重定向及其他操作,而保证这些操作能完成的需要基础组件,通用的字符串处理、事件的回调处理、 HTTP 的通用信息等,最下方的 read and write 则是与 network 打交道的。

  • network 是网络组件,它可以自动选择数据通道,如果是 加密 方式则通过 tls 进行数据传输,而 tls 可以选择 mbedtls 作为加密后端也可以选择 openssl 作为加密后端;也可以是 tcp 直连方式,最终都是通过 tcp 传输的,此外还实现了本地的 routing(或者叫 dns 缓存,加快域名的解析处理)。

  • platform 是平台抽象层,封装了不同系统的东西,比如 socke 或者 AT线程时间互斥锁内存管理,这些是与系统打交道的,也是跨平台必要的封装。

  • 最右边的则是通用的内容,list 列表的处理、日志库错误代码软件随机数发生器 等。

版本

发布版本 描述
[v1.0.0] 初次发布,完成基本架构的及其稳定性验证

文档说明

欢迎各位朋友参与进来开发,所有的功能实现都有详细的文档介绍,大家可以选择 开发计划 中的项目进行开发、探讨、提交PR,也欢迎大家提交功能需求,本项目将由 杰杰 持续维护。

测试代码 & 文档

参与开发

  • 平台:任何 linux 平台,目前先暂时开发 linux 平台的,后续适配其他平台。

安装 cmake 及编译器

sudo apt-get install -y cmake gcc g++

编译

编写好相关的功能后进行编译并测试,main 函数入口在 test/test.c 文件中。

./build.sh

产生的可执行文件在 ./build/bin/http-client 路径下。

运行

 ./build/bin/http-client

观察测试结果,满足要求后提交 PR

如何提交PR?

问题

欢迎以 GitHub Issues 的形式提交功能需求、问题和 bug 报告等。

版权和许可

http-client 遵循 Apache License v2.0 开源协议。鼓励代码共享和尊重原作者的著作权,可以自由的使用、修改源代码,也可以将修改后的代码作为开源或闭源软件发布。

Star & Fork

后续我还会提供更多开源项目。也非常欢迎大家设计、开发更多实用插件和功能,一起来完善 http-client。如果觉得这个开源项目很赞,可以点击项目主页 右上角的 Star & Fork,同时把它推荐给更多有需要的朋友。

感谢参与贡献的开发者

http-client's People

Contributors

jiejietop avatar lintex9527 avatar murphyzhao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

http-client's Issues

HTTP重定向访问时代码BUG导致释放内存被访问异常奔溃

问题点,http_interceptor.c,266行:
参数1:interceptor->connect_params,重定向为新的URL数据
参数2:http_get_connect_params_url(interceptor->connect_params,重定向为新的URL数据同一个地址
http_url_parsing(interceptor->connect_params, http_get_connect_params_url(interceptor->connect_params));
解决办法:
新的的URL数据重新申请内存保存数据作为参数2传入完成URL的重新解析
const char *p_new_url = NULL;
int malloc_len = strlen(http_get_connect_params_url(interceptor->connect_params))+1;
p_new_url =(const char *)platform_memory_alloc(http_get_connect_params_url(malloc_len);
if(!p_new_url ) {
return;
}
memset(p_new_url,0,);
memcpy(p_new_url,http_get_connect_params_url(interceptor->connect_params),strlen(http_get_connect_params_url(interceptor->connect_params));
ret = http_url_parsing(interceptor->connect_params, p_new_url); //这里原来的地址重新申请的时候以及被释放了,所以这里需要拷贝一个新的地址处理
platform_memory_free(p_new_url);

build errro when i use static mode

set(CMAKE_LIB_TYPE "SHARED") STATIC

http-client/platform/linux/platform_net_socket.c:46: undefined reference to `routing_record'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/http-client] Error 1
make[1]: *** [test/CMakeFiles/http-client.dir/all] Error 2
make: *** [all] Error 2

new features/添加新特性

As a client developed in accordance with the standard HTTP protocol, you may need to add new features on some platforms or meet some more convenient needs. You can speak freely here. This project will continue to be maintained.

作为一个按照标准MQTT协议开发的客户端,可能在某些平台上需要添加新的特性,或者满足某些更方便的需求,可以在这里畅所欲言,本项目将持续维护。

client pool

请问 你这里是怎么实现keepalive,如果池里的client长时间没使用,keepalive会失效吧

build error for cross arm-linux-gcc

Scanning dependencies of target arch
[  0%] Building C object common/log/arch/linux/CMakeFiles/arch.dir/arch.c.o
clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
[  1%] Linking C shared library ../../../../lib/libarch.so
ld: unknown option: -soname
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/libarch.so] Error 1
make[1]: *** [common/log/arch/linux/CMakeFiles/arch.dir/all] Error 2
make: *** [all] Error 2

若要发送post数据,并需要设置http头,需要关心哪些API呢?

hi,如果以库的形式使用本项目,对于库的使用者来说,主要关心哪些外部API呢?http-client整个目录都是供用户使用的外部API吗?还是仅仅是test目录属于外部使用?我在开发中,若使用test目录,其仅能发送数据并获取响应,但是项目中需要设置http头,test目录下的示例中并没有提供相应接口?

关于http_config.h文件的处理,以及install选项的问题

@jiejieTop

哈喽,我在一个小的嵌入式程序中使用了本项目,感觉对嵌入式小项目很友好,e。。之前使用libcurl,感觉到的是我们这个项目在响应速度上要比libcurl慢,,也可能是我配置的问题,在我们的小程序中,以动态库的形式使用了本项目作为程序的一部分,说下自己的建议

1.http_config.h感觉应该作为一个单独的配置目录而存在,不应放在test目录中,因为他影响的是整个工程而不是单独的上层测试代码,,针对响应慢的问题,我修改了http_config.h的HTTP_DEFAULT_CMD_TIMEOUT 参数,感觉响应的速度已经满足我们的要求了

2.cmake的install参数似乎并没有设置吗???,我这边如果在工程中使用,,,在一个脚本中用了如下的方法。。。

cp ${HTTP_CLIENT_UNPACK}/platform/linux ${HTTP_CLIENT_INSTALL}/include -Rdf
cp ${HTTP_CLIENT_UNPACK}/test/http_config.h ${HTTP_CLIENT_INSTALL}/include -Rdf
cp ${HTTP_CLIENT_UNPACK}/common ${HTTP_CLIENT_INSTALL}/include -Rdf
cp ${HTTP_CLIENT_UNPACK}/common/log ${HTTP_CLIENT_INSTALL}/include -Rdf
cp ${HTTP_CLIENT_UNPACK}/network/mbedtls/include ${HTTP_CLIENT_INSTALL}/include -Rdf
cp ${HTTP_CLIENT_UNPACK}/network ${HTTP_CLIENT_INSTALL}/include -Rdf
cp ${HTTP_CLIENT_UNPACK}/libhttp ${HTTP_CLIENT_INSTALL}/include -Rdf
cp ${HTTP_CLIENT_UNPACK}/httpclient ${HTTP_CLIENT_INSTALL}/include -Rdf
cp lib ${PREFIX} -Rdf

3.似乎还有些log级别的设置,,即使设置warn level 但是代码中还是有很多的printf,不知是否刻意而为之??

以上,如果需要修改??我可以测试后pr??

Response delayed when accessing HTTPs website

I encountered a problem when using the http-client to access HTTPs website.
It takes about 20 seconds to get response from HTTPs website and the response time is too long.
Does anybody have the same problem when accessing HTTPs website?
What is the possible root cause?
Hope someone can answer for me, thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.