From 2ab93c968003e58791c6b484113e45e7be47ea83 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Tue, 5 Dec 2017 23:26:36 +0800 Subject: [PATCH] Lua template: Optimize code Signed-off-by: Jianhui Zhao --- src/template.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/template.c b/src/template.c index 5b71758..b7550b2 100755 --- a/src/template.c +++ b/src/template.c @@ -626,11 +626,10 @@ void uh_template(struct uh_connection *con) for (i = 0; i < con->req.header_num; i ++) { struct uh_header *h = &con->req.header[i]; - char buf[128] = ""; - snprintf(buf, sizeof(buf), "%.*s", (int)h->field.len, h->field.at); + lua_pushlstring(L, h->field.at, h->field.len); lua_pushlstring(L, h->value.at, h->value.len); - lua_setfield(L, -2, buf); + lua_settable(L, -3); } lua_setfield(L, -2, "HEADERS");