Fix bug: Incorrect use the function uh_con_reuse()

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
main
Jianhui Zhao 2017-11-13 23:36:17 +08:00
parent 64dfcceb28
commit 3d92d0665f
3 changed files with 8 additions and 37 deletions

View File

@ -11,6 +11,7 @@ static void signal_cb(struct ev_loop *loop, ev_signal *w, int revents)
void route_test(struct uh_connection *con)
{
struct uh_value *url = uh_get_url(con);
struct uh_value *path = uh_get_url(con);
struct uh_value *header_host = uh_get_header(con, "Host");
struct uh_value *header_ua = uh_get_header(con, "User-Agent");
@ -18,6 +19,7 @@ void route_test(struct uh_connection *con)
uh_printf_chunk(con, "<h1>Hello World</h1>");
uh_printf_chunk(con, "<h1>Libuhttp v%s</h1>", uh_version());
uh_printf_chunk(con, "<h1>Url: %.*s</h1>", (int)url->len, url->at);
uh_printf_chunk(con, "<h1>Path: %.*s</h1>", (int)path->len, path->at);
if (header_host)
uh_printf_chunk(con, "<h1>Host: %.*s</h1>", (int)header_host->len, header_host->at);

View File

@ -249,10 +249,10 @@ static int on_message_complete(http_parser *parser)
#endif
list_for_each_entry(r, &con->srv->routes, list) {
if (uh_value_cmp(&con->req.url, r->path)) {
if (uh_value_cmp(&con->req.path, r->path)) {
r->cb(con);
if (!(con->flags & UH_CON_CLOSE))
uh_con_reuse(con);
con->flags |= UH_CON_REUSE;
return 0;
}
}
@ -353,6 +353,9 @@ static void connection_write_cb(struct ev_loop *loop, ev_io *w, int revents)
if (!http_should_keep_alive(&con->parser))
con->flags |= UH_CON_CLOSE;
if (con->flags & UH_CON_REUSE)
uh_con_reuse(con);
}
if (con->flags & UH_CON_CLOSE)
@ -642,41 +645,6 @@ inline struct uh_value *uh_get_query(struct uh_connection *con)
return &con->req.query;
}
static inline char c2hex(char c)
{
return c >= '0' && c <= '9' ? c - '0' : c >= 'A' && c <= 'F' ? c - 'A' + 10 : c - 'a' + 10; /* accept small letters just in case */
}
static char *uh_unescape(char *str)
{
char *p = str;
char *q = str;
if (!str)
return ("");
while (*p) {
if (*p == '%') {
p++;
if (*p)
*q = c2hex(*p++) * 16;
if (*p)
*q = (*q + c2hex(*p++));
q++;
} else {
if (*p == '+') {
*q++ = ' ';
p++;
} else {
*q++ = *p++;
}
}
}
*q++ = 0;
return str;
}
struct uh_value *uh_get_header(struct uh_connection *con, const char *name)
{
int i;

View File

@ -16,6 +16,7 @@
#define UH_CON_CLOSE (1 << 0)
#define UH_CON_SSL_HANDSHAKE_DONE (1 << 1) /* SSL hanshake has completed */
#define UH_CON_PARSERING (1 << 2) /* Whether executed http_parser_execute() */
#define UH_CON_REUSE (1 << 3)
#define likely(x) (__builtin_expect(!!(x), 1))
#define unlikely(x) (__builtin_expect(!!(x), 0))