From 162b8fe4f26ea765b78d8e713b8afca4560036e7 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Thu, 2 Jul 2020 22:26:00 +0800 Subject: [PATCH] conn_get_header: return NULL if not found Signed-off-by: Jianhui Zhao --- src/connection.c | 4 ++-- src/file.c | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/connection.c b/src/connection.c index 7142042..c1cfa63 100644 --- a/src/connection.c +++ b/src/connection.c @@ -212,7 +212,7 @@ static const char *conn_get_header(struct uh_connection *conn, const char *name) } if (i == UHTTPD_MAX_HEADER_NUM) - return ""; + return NULL; for (j = 0; j < UHTTPD_MAX_HEADER_NUM; j++) { if (req->headers_info[j].name_offset > 0) { @@ -226,7 +226,7 @@ static const char *conn_get_header(struct uh_connection *conn, const char *name) } } - return ""; + return NULL; } static const char *conn_get_body(struct uh_connection *conn, int *len) diff --git a/src/file.c b/src/file.c index 6530d96..3e4c73f 100644 --- a/src/file.c +++ b/src/file.c @@ -88,7 +88,7 @@ static void file_response_304(struct uh_connection *conn, struct stat *s) static bool file_if_modified_since(struct uh_connection *conn, struct stat *s) { const char *hdr = conn->get_header(conn, "If-Modified-Since"); - if (!hdr[0]) + if (!hdr) return true; if (date2unix(hdr) >= s->st_mtime) { @@ -101,8 +101,7 @@ static bool file_if_modified_since(struct uh_connection *conn, struct stat *s) static bool file_if_range(struct uh_connection *conn, struct stat *s) { - const char *hdr = conn->get_header(conn, "If-Range"); - if (hdr[0]) { + if (conn->get_header(conn, "If-Range")) { conn->error(conn, HTTP_STATUS_PRECONDITION_FAILED, NULL); return false; } @@ -113,7 +112,7 @@ static bool file_if_range(struct uh_connection *conn, struct stat *s) static bool file_if_unmodified_since(struct uh_connection *conn, struct stat *s) { const char *hdr = conn->get_header(conn, "If-Modified-Since"); - if (hdr[0] && date2unix(hdr) <= s->st_mtime) { + if (hdr && date2unix(hdr) <= s->st_mtime) { conn->error(conn, HTTP_STATUS_PRECONDITION_FAILED, NULL); return false; }