Browse Source

Reqrite request parsing (Step 13/?)

bel2125 8 years ago
parent
commit
87cb327b99
2 changed files with 9 additions and 8 deletions
  1. 2 2
      src/civetweb.c
  2. 7 6
      test/private.c

+ 2 - 2
src/civetweb.c

@@ -6501,14 +6501,14 @@ get_http_header_len(const char *buf, int buflen)
 		if ((buf[i] == '\n') && (buf[i + 1] == '\n')) {
 		if ((buf[i] == '\n') && (buf[i + 1] == '\n')) {
 			/* Two newline, no carriage return - not standard compliant, but it
 			/* Two newline, no carriage return - not standard compliant, but it
 			 * should be accepted */
 			 * should be accepted */
-            return i + 2;
+			return i + 2;
 		}
 		}
 
 
 		if (i < buflen - 3) {
 		if (i < buflen - 3) {
 			if ((buf[i] == '\r') && (buf[i + 1] == '\n') && (buf[i + 2] == '\r')
 			if ((buf[i] == '\r') && (buf[i + 1] == '\n') && (buf[i + 2] == '\r')
 			    && (buf[i + 3] == '\n')) {
 			    && (buf[i + 3] == '\n')) {
 				/* Two \r\n - standard compliant */
 				/* Two \r\n - standard compliant */
-                return i + 4;
+				return i + 4;
 			}
 			}
 		}
 		}
 	}
 	}

+ 7 - 6
test/private.c

@@ -58,7 +58,7 @@ START_TEST(test_parse_http_message)
 	char empty[] = "";
 	char empty[] = "";
 	char req1[] = "GET / HTTP/1.1\r\n\r\n";
 	char req1[] = "GET / HTTP/1.1\r\n\r\n";
 	char req2[] = "BLAH / HTTP/1.1\r\n\r\n";
 	char req2[] = "BLAH / HTTP/1.1\r\n\r\n";
-	char req3[] = "GET / HTTP/1.1\r\nBah\r\n";
+	char req3[] = "GET / HTTP/1.1\nKey: Val\n\n";
 	char req4[] =
 	char req4[] =
 	    "GET / HTTP/1.1\r\nA: foo bar\r\nB: bar\r\nskip\r\nbaz:\r\n\r\n";
 	    "GET / HTTP/1.1\r\nA: foo bar\r\nB: bar\r\nskip\r\nbaz:\r\n\r\n";
 	char req5[] = "GET / HTTP/1.1\r\n\r\n";
 	char req5[] = "GET / HTTP/1.1\r\n\r\n";
@@ -76,6 +76,7 @@ START_TEST(test_parse_http_message)
 	ck_assert_int_eq(0, parse_http_request(empty, 0, &ri));
 	ck_assert_int_eq(0, parse_http_request(empty, 0, &ri));
 
 
 
 
+	ck_assert_int_eq(0, get_http_header_len(req1, (int)strlen(req1) - 1));
 	ck_assert_int_eq((int)strlen(req1),
 	ck_assert_int_eq((int)strlen(req1),
 	                 get_http_header_len(req1, (int)strlen(req1)));
 	                 get_http_header_len(req1, (int)strlen(req1)));
 	ck_assert_int_eq((int)strlen(req1),
 	ck_assert_int_eq((int)strlen(req1),
@@ -163,8 +164,8 @@ START_TEST(test_should_keep_alive)
 
 
 	memset(&conn, 0, sizeof(conn));
 	memset(&conn, 0, sizeof(conn));
 	conn.ctx = &ctx;
 	conn.ctx = &ctx;
-	ck_assert_int_eq(parse_http_request(req1, sizeof(req1), &conn.request_info),
-	                 sizeof(req1) - 1);
+	ck_assert_int_eq(parse_http_request(req1, strlen(req1), &conn.request_info),
+	                 strlen(req1));
 
 
 	ctx.config[ENABLE_KEEP_ALIVE] = no;
 	ctx.config[ENABLE_KEEP_ALIVE] = no;
 	ck_assert_int_eq(should_keep_alive(&conn), 0);
 	ck_assert_int_eq(should_keep_alive(&conn), 0);
@@ -176,13 +177,13 @@ START_TEST(test_should_keep_alive)
 	ck_assert_int_eq(should_keep_alive(&conn), 0);
 	ck_assert_int_eq(should_keep_alive(&conn), 0);
 
 
 	conn.must_close = 0;
 	conn.must_close = 0;
-	parse_http_request(req2, sizeof(req2), &conn.request_info);
+	parse_http_request(req2, strlen(req2), &conn.request_info);
 	ck_assert_int_eq(should_keep_alive(&conn), 0);
 	ck_assert_int_eq(should_keep_alive(&conn), 0);
 
 
-	parse_http_request(req3, sizeof(req3), &conn.request_info);
+	parse_http_request(req3, strlen(req3), &conn.request_info);
 	ck_assert_int_eq(should_keep_alive(&conn), 0);
 	ck_assert_int_eq(should_keep_alive(&conn), 0);
 
 
-	parse_http_request(req4, sizeof(req4), &conn.request_info);
+	parse_http_request(req4, strlen(req4), &conn.request_info);
 	ck_assert_int_eq(should_keep_alive(&conn), 1);
 	ck_assert_int_eq(should_keep_alive(&conn), 1);
 
 
 	conn.status_code = 401;
 	conn.status_code = 401;