Optimization function name
Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>main
parent
622ff0c03f
commit
6f756b6d99
|
@ -103,7 +103,7 @@ int main(int argc, char **argv)
|
|||
|
||||
ULOG_INFO("Listen on: %s *:%d\n", srv->ssl ? "https" : "http", port);
|
||||
|
||||
srv->request_cb = on_request;
|
||||
srv->on_request = on_request;
|
||||
|
||||
uloop_run();
|
||||
done:
|
||||
|
|
|
@ -41,7 +41,7 @@ local srv = uh.new(port)
|
|||
|
||||
uh.log(uh.LOG_INFO, "Listen on:" .. port)
|
||||
|
||||
srv:set_error404_cb(function(cl, path)
|
||||
srv:set_on_error404(function(cl, path)
|
||||
uh.send_header(cl, 200, "OK", -1)
|
||||
uh.header_end(cl)
|
||||
|
||||
|
@ -61,7 +61,7 @@ local http_version = {
|
|||
[uh.HTTP_VER_11] = "HTTP/1.1"
|
||||
}
|
||||
|
||||
srv:set_request_cb(function(cl, path)
|
||||
srv:set_on_request(function(cl, path)
|
||||
if path ~= "/hello" then
|
||||
return uh.REQUEST_CONTINUE
|
||||
end
|
||||
|
|
|
@ -99,7 +99,7 @@ int main(int argc, char **argv)
|
|||
|
||||
ULOG_INFO("Listen on: %s *:%d\n", srv->ssl ? "https" : "http", port);
|
||||
|
||||
srv->request_cb = on_request;
|
||||
srv->on_request = on_request;
|
||||
|
||||
uloop_run();
|
||||
done:
|
||||
|
|
14
src/client.c
14
src/client.c
|
@ -179,14 +179,14 @@ static void post_post_done(struct uh_client *cl)
|
|||
{
|
||||
char *path = kvlist_get(&cl->request.url, "path");
|
||||
|
||||
if (cl->srv->request_cb(cl) == UH_REQUEST_DONE)
|
||||
if (cl->srv->on_request(cl) == UH_REQUEST_DONE)
|
||||
return;
|
||||
|
||||
if (handle_file_request(cl, path))
|
||||
return;
|
||||
|
||||
if (cl->srv->error404_cb) {
|
||||
cl->srv->error404_cb(cl);
|
||||
if (cl->srv->on_error404) {
|
||||
cl->srv->on_error404(cl);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -203,12 +203,12 @@ static void uh_handle_request(struct uh_client *cl)
|
|||
{
|
||||
char *path = kvlist_get(&cl->request.url, "path");
|
||||
|
||||
if (cl->srv->request_cb) {
|
||||
if (cl->srv->on_request) {
|
||||
struct dispatch *d = &cl->dispatch;
|
||||
|
||||
switch (cl->request.method) {
|
||||
case UH_HTTP_METHOD_GET:
|
||||
if (cl->srv->request_cb(cl) == UH_REQUEST_DONE)
|
||||
if (cl->srv->on_request(cl) == UH_REQUEST_DONE)
|
||||
return;
|
||||
break;
|
||||
case UH_HTTP_METHOD_POST:
|
||||
|
@ -228,8 +228,8 @@ static void uh_handle_request(struct uh_client *cl)
|
|||
if (handle_file_request(cl, path))
|
||||
return;
|
||||
|
||||
if (cl->srv->error404_cb) {
|
||||
cl->srv->error404_cb(cl);
|
||||
if (cl->srv->on_error404) {
|
||||
cl->srv->on_error404(cl);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,8 +51,8 @@ static int lua_uh_on_request(struct uh_client *cl)
|
|||
const char *path = cl->get_path(cl);
|
||||
lua_State *L = cl->srv->L;
|
||||
|
||||
lua_getglobal(L, "__uh_request_cb");
|
||||
lua_rawgeti(L, -1, lsrv->request_cb_ref);
|
||||
lua_getglobal(L, "__uh_on_request");
|
||||
lua_rawgeti(L, -1, lsrv->request_ref);
|
||||
lua_remove(L, -2);
|
||||
|
||||
lua_pushlightuserdata(L, cl);
|
||||
|
@ -80,17 +80,17 @@ static int lua_uh_ssl_init(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int lua_uh_set_request_cb(lua_State *L)
|
||||
static int lua_uh_set_on_request(lua_State *L)
|
||||
{
|
||||
struct lua_uh_server *lsrv = luaL_checkudata(L, 1, LUA_UH_SERVER_MT);
|
||||
|
||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
||||
|
||||
lua_getglobal(L, "__uh_request_cb");
|
||||
lua_getglobal(L, "__uh_on_request");
|
||||
lua_pushvalue(L, 2);
|
||||
lsrv->request_cb_ref = luaL_ref(L, -2);
|
||||
lsrv->request_ref = luaL_ref(L, -2);
|
||||
|
||||
lsrv->srv.request_cb = lua_uh_on_request;
|
||||
lsrv->srv.on_request = lua_uh_on_request;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -101,8 +101,8 @@ static void http_callback_404(struct uh_client *cl)
|
|||
const char *path = cl->get_path(cl);
|
||||
lua_State *L = cl->srv->L;
|
||||
|
||||
lua_getglobal(L, "__uh_error404_cb");
|
||||
lua_rawgeti(L, -1, lsrv->error404_cb_ref);
|
||||
lua_getglobal(L, "__uh_on_error404");
|
||||
lua_rawgeti(L, -1, lsrv->error404_ref);
|
||||
lua_remove(L, -2);
|
||||
|
||||
lua_pushlightuserdata(L, cl);
|
||||
|
@ -111,17 +111,17 @@ static void http_callback_404(struct uh_client *cl)
|
|||
lua_call(L, 2, 0);
|
||||
}
|
||||
|
||||
static int lua_uh_set_error404_cb(lua_State *L)
|
||||
static int lua_uh_set_on_error404(lua_State *L)
|
||||
{
|
||||
struct lua_uh_server *lsrv = luaL_checkudata(L, 1, LUA_UH_SERVER_MT);
|
||||
|
||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
||||
|
||||
lua_getglobal(L, "__uh_error404_cb");
|
||||
lua_getglobal(L, "__uh_on_error404");
|
||||
lua_pushvalue(L, 2);
|
||||
lsrv->error404_cb_ref = luaL_ref(L, -2);
|
||||
lsrv->error404_ref = luaL_ref(L, -2);
|
||||
|
||||
lsrv->srv.error404_cb = http_callback_404;
|
||||
lsrv->srv.on_error404 = http_callback_404;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -157,8 +157,8 @@ static int lua_uh_server_free(lua_State *L)
|
|||
|
||||
static const luaL_Reg server_mt[] = {
|
||||
{ "ssl_init", lua_uh_ssl_init },
|
||||
{ "set_request_cb", lua_uh_set_request_cb },
|
||||
{ "set_error404_cb", lua_uh_set_error404_cb },
|
||||
{ "set_on_request", lua_uh_set_on_request },
|
||||
{ "set_on_error404", lua_uh_set_on_error404 },
|
||||
{ "set_options", lua_uh_set_options },
|
||||
{ "free", lua_uh_server_free },
|
||||
{ NULL, NULL }
|
||||
|
@ -441,10 +441,10 @@ static const luaL_Reg uhttpd_fun[] = {
|
|||
int luaopen_uhttpd(lua_State *L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
lua_setglobal(L, "__uh_request_cb");
|
||||
lua_setglobal(L, "__uh_on_request");
|
||||
|
||||
lua_newtable(L);
|
||||
lua_setglobal(L, "__uh_error404_cb");
|
||||
lua_setglobal(L, "__uh_on_error404");
|
||||
|
||||
lua_newtable(L);
|
||||
luaL_setfuncs(L, uhttpd_fun, 0);
|
||||
|
|
|
@ -35,8 +35,8 @@
|
|||
|
||||
struct lua_uh_server {
|
||||
struct uh_server srv;
|
||||
int error404_cb_ref;
|
||||
int request_cb_ref;
|
||||
int error404_ref;
|
||||
int request_ref;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -572,8 +572,8 @@ void uh_template(struct uh_client *cl)
|
|||
|
||||
pi = uh_path_lookup(cl, path);
|
||||
if (!pi) {
|
||||
if (cl->srv->error404_cb) {
|
||||
cl->srv->error404_cb(cl);
|
||||
if (cl->srv->on_error404) {
|
||||
cl->srv->on_error404(cl);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ struct uh_server {
|
|||
void (*free)(struct uh_server *srv);
|
||||
void (*set_docroot)(struct uh_server *srv, const char *docroot);
|
||||
void (*set_index_file)(struct uh_server *srv, const char *index_file);
|
||||
void (*error404_cb)(struct uh_client *cl);
|
||||
int (*request_cb)(struct uh_client *cl);
|
||||
void (*on_error404)(struct uh_client *cl);
|
||||
int (*on_request)(struct uh_client *cl);
|
||||
|
||||
#if (UHTTPD_SSL_SUPPORT)
|
||||
int (*ssl_init)(struct uh_server *srv, const char *key, const char *crt);
|
||||
|
|
Loading…
Reference in New Issue