parent
52f35b9109
commit
5635739412
92
README.md
92
README.md
|
@ -30,7 +30,6 @@ from [uhttpd] for Embedded Linux.
|
||||||
`Keep Watching for More Actions on This Space`
|
`Keep Watching for More Actions on This Space`
|
||||||
|
|
||||||
# Features
|
# Features
|
||||||
* Action - processes requests by invoking registered C functions which mapped to a specific path.
|
|
||||||
* Lightweight and fully asynchronous
|
* Lightweight and fully asynchronous
|
||||||
* Use [libubox] as its event backend
|
* Use [libubox] as its event backend
|
||||||
* Support HTTPS - OpenSSL, mbedtls and CyaSSl(wolfssl)
|
* Support HTTPS - OpenSSL, mbedtls and CyaSSl(wolfssl)
|
||||||
|
@ -39,9 +38,6 @@ from [uhttpd] for Embedded Linux.
|
||||||
* Lua Template - Embed Lua code into HTML code, like embedding PHP into HTML
|
* Lua Template - Embed Lua code into HTML code, like embedding PHP into HTML
|
||||||
* Lua binding
|
* Lua binding
|
||||||
|
|
||||||
# TO DO
|
|
||||||
* Lua API - Using Lua programming
|
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
* [libubox]
|
* [libubox]
|
||||||
* [ustream-ssl] - If you need to support SSL
|
* [ustream-ssl] - If you need to support SSL
|
||||||
|
@ -76,93 +72,7 @@ Then use the command curl or browser to test
|
||||||
|
|
||||||
If the install command fails, you can [compile it yourself](/BUILDOPENWRT.md).
|
If the install command fails, you can [compile it yourself](/BUILDOPENWRT.md).
|
||||||
|
|
||||||
# Example
|
# [Example](/example)
|
||||||
```
|
|
||||||
#include <uhttpd.h>
|
|
||||||
|
|
||||||
static void hello_action(struct uh_client *cl)
|
|
||||||
{
|
|
||||||
int body_len = 0;
|
|
||||||
|
|
||||||
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>URL: %s</h1>", cl->get_url(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->chunk_printf(cl, "<h1>VAR name: %s</h1>", cl->get_var(cl, "name"));
|
|
||||||
cl->chunk_printf(cl, "<h1>BODY:%s</h1>", cl->get_body(cl, &body_len));
|
|
||||||
cl->request_done(cl);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void usage(const char *prog)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Usage: %s [option]\n"
|
|
||||||
" -p port # Default port is 8080\n"
|
|
||||||
" -s # SSl on\n"
|
|
||||||
" -v # verbose\n", prog);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
struct uh_server *srv = NULL;
|
|
||||||
int verbose = false;
|
|
||||||
int ssl = false;
|
|
||||||
int port = 8080;
|
|
||||||
int opt;
|
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "p:vs")) != -1) {
|
|
||||||
switch (opt)
|
|
||||||
{
|
|
||||||
case 'p':
|
|
||||||
port = atoi(optarg);
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
ssl = true;
|
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
verbose = true;
|
|
||||||
break;
|
|
||||||
default: /* '?' */
|
|
||||||
usage(argv[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!verbose)
|
|
||||||
ulog_threshold(LOG_ERR);
|
|
||||||
|
|
||||||
uh_log_debug("libuhttpd version: %s", UHTTPD_VERSION_STRING);
|
|
||||||
|
|
||||||
uloop_init();
|
|
||||||
|
|
||||||
srv = uh_server_new("0.0.0.0", port);
|
|
||||||
if (!srv)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
#if (!UHTTPD_SSL_SUPPORT)
|
|
||||||
if (ssl)
|
|
||||||
uh_log_debug("SSl is not compiled in");
|
|
||||||
#else
|
|
||||||
if (ssl && srv->ssl_init(srv, "server-key.pem", "server-cert.pem") < 0)
|
|
||||||
goto done;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uh_log_debug("Listen on: %s *:%d", srv->ssl ? "https" : "http", port);
|
|
||||||
|
|
||||||
srv->add_action(srv, "/hello", hello_action);
|
|
||||||
|
|
||||||
uloop_run();
|
|
||||||
done:
|
|
||||||
uloop_done();
|
|
||||||
srv->free(srv);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
# Contributing
|
# Contributing
|
||||||
If you would like to help making [libuhttpd](https://github.com/zhaojh329/libuhttpd) better,
|
If you would like to help making [libuhttpd](https://github.com/zhaojh329/libuhttpd) better,
|
||||||
|
|
94
README_ZH.md
94
README_ZH.md
|
@ -29,17 +29,13 @@
|
||||||
`请保持关注以获取最新的项目动态`
|
`请保持关注以获取最新的项目动态`
|
||||||
|
|
||||||
# 特性
|
# 特性
|
||||||
* Action - 通过调用映射到特定路径的已注册C函数来处理请求。
|
|
||||||
* 轻量、全异步
|
* 轻量、全异步
|
||||||
* 使用[libubox]作为其事件后端
|
* 使用[libubox]作为其事件后端
|
||||||
* 支持HTTPS - OpenSSL, mbedtls 和 CyaSSl(wolfssl)
|
* 支持HTTPS - OpenSSL, mbedtls 和 CyaSSl(wolfssl)
|
||||||
* 可伸缩 - 你可以非常方便的扩展你的应用程序,使之具备HTTP/HTTPS服务
|
* 可伸缩 - 你可以非常方便的扩展你的应用程序,使之具备HTTP/HTTPS服务
|
||||||
* 代码结构简洁通俗易懂,亦适合学习
|
* 代码结构简洁通俗易懂,亦适合学习
|
||||||
* Lua模板 - 嵌入LUA代码到HTML中,就像嵌入PHP到HTML中一样
|
* Lua模板 - 嵌入LUA代码到HTML中,就像嵌入PHP到HTML中一样
|
||||||
* Lua binding
|
* Lua绑定
|
||||||
|
|
||||||
# 计划支持
|
|
||||||
* Lua API - 使用Lua编程
|
|
||||||
|
|
||||||
# 依赖
|
# 依赖
|
||||||
* [libubox]
|
* [libubox]
|
||||||
|
@ -75,93 +71,7 @@
|
||||||
|
|
||||||
如果安装失败,你可以[自己编译](/BUILDOPENWRT_ZH.md)。
|
如果安装失败,你可以[自己编译](/BUILDOPENWRT_ZH.md)。
|
||||||
|
|
||||||
# 示例程序
|
# [示例程序](/example)
|
||||||
```
|
|
||||||
#include <uhttpd.h>
|
|
||||||
|
|
||||||
static void hello_action(struct uh_client *cl)
|
|
||||||
{
|
|
||||||
int body_len = 0;
|
|
||||||
|
|
||||||
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>URL: %s</h1>", cl->get_url(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->chunk_printf(cl, "<h1>VAR name: %s</h1>", cl->get_var(cl, "name"));
|
|
||||||
cl->chunk_printf(cl, "<h1>BODY:%s</h1>", cl->get_body(cl, &body_len));
|
|
||||||
cl->request_done(cl);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void usage(const char *prog)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Usage: %s [option]\n"
|
|
||||||
" -p port # Default port is 8080\n"
|
|
||||||
" -s # SSl on\n"
|
|
||||||
" -v # verbose\n", prog);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
struct uh_server *srv = NULL;
|
|
||||||
int verbose = false;
|
|
||||||
int ssl = false;
|
|
||||||
int port = 8080;
|
|
||||||
int opt;
|
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "p:vs")) != -1) {
|
|
||||||
switch (opt)
|
|
||||||
{
|
|
||||||
case 'p':
|
|
||||||
port = atoi(optarg);
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
ssl = true;
|
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
verbose = true;
|
|
||||||
break;
|
|
||||||
default: /* '?' */
|
|
||||||
usage(argv[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!verbose)
|
|
||||||
ulog_threshold(LOG_ERR);
|
|
||||||
|
|
||||||
uh_log_debug("libuhttpd version: %s", UHTTPD_VERSION_STRING);
|
|
||||||
|
|
||||||
uloop_init();
|
|
||||||
|
|
||||||
srv = uh_server_new("0.0.0.0", port);
|
|
||||||
if (!srv)
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
#if (!UHTTPD_SSL_SUPPORT)
|
|
||||||
if (ssl)
|
|
||||||
uh_log_debug("SSl is not compiled in");
|
|
||||||
#else
|
|
||||||
if (ssl && srv->ssl_init(srv, "server-key.pem", "server-cert.pem") < 0)
|
|
||||||
goto done;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uh_log_debug("Listen on: %s *:%d", srv->ssl ? "https" : "http", port);
|
|
||||||
|
|
||||||
srv->add_action(srv, "/hello", hello_action);
|
|
||||||
|
|
||||||
uloop_run();
|
|
||||||
done:
|
|
||||||
uloop_done();
|
|
||||||
srv->free(srv);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
# 贡献代码
|
# 贡献代码
|
||||||
如果你想帮助[libuhttpd](https://github.com/zhaojh329/libuhttpd)变得更好,请参考
|
如果你想帮助[libuhttpd](https://github.com/zhaojh329/libuhttpd)变得更好,请参考
|
||||||
|
|
Loading…
Reference in New Issue