From bec72d277d1fa6216cc0029ce60f244d05dc38cb Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Wed, 29 Nov 2017 14:42:46 +0800 Subject: [PATCH] Optimize the function 'uh_get_var()' Signed-off-by: Jianhui Zhao --- src/uhttp.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/uhttp.c b/src/uhttp.c index 82143cc..64b813e 100755 --- a/src/uhttp.c +++ b/src/uhttp.c @@ -605,14 +605,21 @@ int uh_unescape(const char *str, int len, char *out, int olen) struct uh_str uh_get_var(struct uh_connection *con, const char *name) { struct uh_str *query = &con->req.query; - const char *pos = query->at, *tail = query->at + query->len - 1; - const char *p, *q; + struct uh_str *body = &con->req.body; + const char *pos, *tail, *p, *q; struct uh_str var = {.at = NULL, .len = 0}; - assert(con && name); - - if (query->len == 0) + if (query->len > 0) { + pos = query->at; + tail = query->at + query->len - 1; + } else if (body->len > 0) { + pos = body->at; + tail = body->at + body->len - 1; + } else { return var; + } + + assert(con && name); while (pos < tail) { p = memchr(pos, '&', tail - pos);