Prechádzať zdrojové kódy

Rewrite request parsing (Step 24/?)

bel2125 8 rokov pred
rodič
commit
9c1cf97c3a
2 zmenil súbory, kde vykonal 19 pridanie a 2 odobranie
  1. 5 0
      src/civetweb.c
  2. 14 2
      test/private.c

+ 5 - 0
src/civetweb.c

@@ -3318,6 +3318,7 @@ get_http_version(const struct mg_connection *conn)
 	return NULL;
 }
 
+
 /* A helper function for traversing a comma separated list of values.
  * It returns a list pointer shifted to the next value, or NULL if the end
  * of the list found.
@@ -3376,6 +3377,7 @@ reparse:
 	return list;
 }
 
+
 /* A helper function for checking if a comma separated list of values contains
  * the given option (case insensitvely).
  * 'header' can be NULL, in which case false is returned. */
@@ -3385,8 +3387,10 @@ header_has_option(const char *header, const char *option)
 	struct vec opt_vec;
 	struct vec eq_vec;
 
+	/*
 	assert(option != NULL);
 	assert(option[0] != '\0');
+	*/
 
 	while ((header = next_option(header, &opt_vec, &eq_vec)) != NULL) {
 		if (mg_strncasecmp(option, opt_vec.ptr, opt_vec.len) == 0)
@@ -3396,6 +3400,7 @@ header_has_option(const char *header, const char *option)
 	return 0;
 }
 
+
 /* Perform case-insensitive match of string against pattern */
 static int
 match_prefix(const char *pattern, size_t pattern_len, const char *str)

+ 14 - 2
test/private.c

@@ -234,10 +234,13 @@ START_TEST(test_should_keep_alive)
 	int lenreq4 = (int)strlen(req4);
 
 
+	memset(&ctx, 0, sizeof(ctx));
 	memset(&conn, 0, sizeof(conn));
 	conn.ctx = &ctx;
 	ck_assert_int_eq(test_parse_http_request(req1, lenreq1, &conn.request_info),
 	                 lenreq1);
+	conn.connection_type = 1; /* Valid request */
+	ck_assert_int_eq(conn.request_info.num_headers, 0);
 
 	ctx.config[ENABLE_KEEP_ALIVE] = no;
 	ck_assert_int_eq(should_keep_alive(&conn), 0);
@@ -250,16 +253,25 @@ START_TEST(test_should_keep_alive)
 
 	conn.must_close = 0;
 	test_parse_http_request(req2, lenreq2, &conn.request_info);
+	conn.connection_type = 1; /* Valid request */
+	ck_assert_int_eq(conn.request_info.num_headers, 0);
 	ck_assert_int_eq(should_keep_alive(&conn), 0);
 
 	test_parse_http_request(req3, lenreq3, &conn.request_info);
+	conn.connection_type = 1; /* Valid request */
+	ck_assert_int_eq(conn.request_info.num_headers, 1);
 	ck_assert_int_eq(should_keep_alive(&conn), 0);
 
 	test_parse_http_request(req4, lenreq4, &conn.request_info);
+	conn.connection_type = 1; /* Valid request */
+	ck_assert_int_eq(conn.request_info.num_headers, 1);
 	ck_assert_int_eq(should_keep_alive(&conn), 1);
 
-	conn.status_code = 401;
-	ck_assert_int_eq(should_keep_alive(&conn), 0);
+	/* No longer required. Server sets must_close if status is 401
+
+	    conn.status_code = 401;
+	    ck_assert_int_eq(should_keep_alive(&conn), 0);
+	*/
 
 	conn.status_code = 200;
 	conn.must_close = 1;