libuhttpd/README_ZH.md

105 lines
2.7 KiB
Markdown
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# libuhttp
![](https://img.shields.io/badge/license-GPLV3-brightgreen.svg?style=plastic "License")
[libubox]: https://git.lede-project.org/?p=project/libubox.git
[uhttpd]: https://git.lede-project.org/?p=project/uhttpd.git
[ustream-ssl]: https://git.lede-project.org/?p=project/ustream-ssl.git
[openssl]: https://github.com/openssl/openssl
[mbedtls]: https://github.com/ARMmbed/mbedtls
[CyaSSl(wolfssl)]: https://github.com/wolfSSL/wolfssl
一个专门针对嵌入式Linux的非常小巧且快速的HTTP服务器C库基于[libubox],参考了[uhttpd]。
`请保持关注以获取最新的项目动态`
# 特性
* 小巧且快速
* 使用[libubox]作为其事件后端
* 支持HTTPS: OpenSSL, mbedtls and CyaSSl(wolfssl)
* 可伸缩你可以非常方便的扩展你的应用程序使之具备HTTP/HTTPS服务
* 代码结构简洁通俗易懂,亦适合学习
# 依赖
* [libubox]
* [ustream-ssl]: 如果你需要支持SSL
* [mbedtls]: 如果你选择mbedtls作为你的SSL后端
* [CyaSSl(wolfssl)]: 如果你选择wolfssl作为你的SSL后端
* [openssl]: 如果你选择openssl作为你的SSL后端
## 配置
查看支持哪些配置选项
~/libuhttpd/build$ cmake .. -L
~/libuhttpd/build$ cmake .. -LH
## 运行例子
首先生成SSL证书文件
~/libuhttpd/build$ cd ..
~/libuhttpd$ ./gen_cert.sh
运行
~/libuhttpd$ ./build/example/helloworld
然后使用命令curl或者浏览器进行测试
$ curl -k 'https://127.0.0.1:8000/hello?name=test' -v
# 示例程序]
```
#include <uhttpd.h>
#define port "8000"
static void hello_action(struct uh_client *cl)
{
cl->send_header(cl, 200, "OK", -1);
cl->append_header(cl, "Myheader", "Hello");
cl->header_end(cl);
cl->chunk_printf(cl, "<h1>Hello Libuhttpd %s</h1>", UHTTPD_VERSION_STRING);
cl->chunk_printf(cl, "<h1>REMOTE_ADDR: %s</h1>", cl->get_peer_addr(cl));
cl->chunk_printf(cl, "<h1>PATH: %s</h1>", cl->get_path(cl));
cl->chunk_printf(cl, "<h1>QUERY: %s</h1>", cl->get_query(cl));
cl->request_done(cl);
}
int main(int argc, char **argv)
{
struct uh_server *srv = NULL;
uh_log_debug("libuhttpd version: %s", UHTTPD_VERSION_STRING);
uloop_init();
srv = uh_server_new("0.0.0.0", port);
if (!srv)
goto done;
uh_log_debug("Listen on: *:%s", port);
#if (UHTTPD_SSL_SUPPORT)
if (srv->ssl_init(srv, "server-key.pem", "server-cert.pem") < 0)
goto done;
#endif
uh_add_action(srv, "/hello", hello_action);
uloop_run();
done:
uloop_done();
srv->free(srv);
return 0;
}
```
# 贡献代码
如果你想帮助[libuhttpd](https://github.com/zhaojh329/libuhttpd)变得更好,请参考
[CONTRIBUTING_ZH.md](https://github.com/zhaojh329/libuhttpd/blob/master/CONTRIBUTING_ZH.md)。
# 技术交流
QQ群153530783