Browse Source

Rewrite request parsing (Step 18/?)

bel2125 8 years ago
parent
commit
3a7fed2d33
2 changed files with 18 additions and 4 deletions
  1. 12 2
      src/civetweb.c
  2. 6 2
      test/public_server.c

+ 12 - 2
src/civetweb.c

@@ -8762,13 +8762,18 @@ parse_http_request(char *buf, int len, struct mg_request_info *ri)
 
 	/* RFC says that all initial whitespaces should be ingored */
 	/* This included all leading \r and \n (isspace) */
-    /* See table: http://www.cplusplus.com/reference/cctype/ */
+	/* See table: http://www.cplusplus.com/reference/cctype/ */
 	while ((len > 0) && isspace(*(unsigned char *)buf)) {
 		buf++;
 		len--;
 		init_skip++;
 	}
 
+	if (len == 0) {
+		/* Incomplete request */
+		return 0;
+	}
+
 	/* Control characters are not allowed, including zero */
 	if (iscntrl(*(unsigned char *)buf)) {
 		return -1;
@@ -8844,13 +8849,18 @@ parse_http_response(char *buf, int len, struct mg_response_info *ri)
 
 	/* RFC says that all initial whitespaces should be ingored */
 	/* This included all leading \r and \n (isspace) */
-    /* See table: http://www.cplusplus.com/reference/cctype/ */
+	/* See table: http://www.cplusplus.com/reference/cctype/ */
 	while ((len > 0) && isspace(*(unsigned char *)buf)) {
 		buf++;
 		len--;
 		init_skip++;
 	}
 
+	if (len == 0) {
+		/* Incomplete request */
+		return 0;
+	}
+
 	/* Control characters are not allowed, including zero */
 	if (iscntrl(*(unsigned char *)buf)) {
 		return -1;

+ 6 - 2
test/public_server.c

@@ -4024,8 +4024,12 @@ test_mg_store_body_begin_request_callback(struct mg_connection *conn)
 {
 	const struct mg_request_info *info = mg_get_request_info(conn);
 
-	if (strcmp(info->request_method, "PUT") == 0
-	    || strcmp(info->request_method, "DELETE") == 0) {
+	/* Debug output for tests */
+	printf("test_mg_store_body_begin_request_callback called (%s)\n",
+	       info->request_method);
+
+	if ((strcmp(info->request_method, "PUT") == 0)
+	    || (strcmp(info->request_method, "DELETE") == 0)) {
 		return test_mg_store_body_put_delete_handler(conn, NULL);
 	}
 	return 0;