Skip to content

Commit

Permalink
conn_get_header: return NULL if not found
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
  • Loading branch information
zhaojh329 committed Jul 2, 2020
1 parent 2844706 commit 162b8fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 162b8fe

Please sign in to comment.