Browse Source

Reset content length and format code

bel2125 7 years ago
parent
commit
195755118a
3 changed files with 8 additions and 8 deletions
  1. 6 7
      src/civetweb.c
  2. 1 1
      test/main.c
  3. 1 0
      test/public_server.c

+ 6 - 7
src/civetweb.c

@@ -5905,11 +5905,11 @@ mg_read_inner(struct mg_connection *conn, void *buf, size_t len)
 	/* If Content-Length is not set for a request with body data
 	/* If Content-Length is not set for a request with body data
 	 * (e.g., a PUT or POST request), we do not know in advance
 	 * (e.g., a PUT or POST request), we do not know in advance
 	 * how much data should be read. */
 	 * how much data should be read. */
-	if ((conn->consumed_content == 0) && (conn->content_len == -1)) {
-		if (conn->is_chunked) {
-			conn->content_len = 0;
+	if (conn->consumed_content == 0) {
+		if (conn->is_chunked == 1) {
+			conn->content_len = len64;
 			conn->is_chunked = 2;
 			conn->is_chunked = 2;
-		} else {
+		} else if (conn->content_len == -1) {
 			/* The body data is completed when the connection
 			/* The body data is completed when the connection
 			 * is closed. */
 			 * is closed. */
 			conn->content_len = INT64_MAX;
 			conn->content_len = INT64_MAX;
@@ -5985,7 +5985,6 @@ mg_read(struct mg_connection *conn, void *buf, size_t len)
 		size_t all_read = 0;
 		size_t all_read = 0;
 
 
 		while (len > 0) {
 		while (len > 0) {
-
 			if (conn->is_chunked == 3) {
 			if (conn->is_chunked == 3) {
 				/* No more data left to read */
 				/* No more data left to read */
 				return 0;
 				return 0;
@@ -10122,7 +10121,7 @@ handle_cgi_request(struct mg_connection *conn, const char *prog)
 	setbuf(err, NULL);
 	setbuf(err, NULL);
 	fout.access.fp = out;
 	fout.access.fp = out;
 
 
-	if ((conn->request_info.content_length > 0) || (conn->is_chunked)) {
+	if ((conn->request_info.content_length != 0) || (conn->is_chunked)) {
 		/* This is a POST/PUT request, or another request with body data. */
 		/* This is a POST/PUT request, or another request with body data. */
 		if (!forward_body_data(conn, in, INVALID_SOCKET, NULL)) {
 		if (!forward_body_data(conn, in, INVALID_SOCKET, NULL)) {
 			/* Error sending the body data */
 			/* Error sending the body data */
@@ -14406,6 +14405,7 @@ reset_per_request_attributes(struct mg_connection *conn)
 
 
 	conn->path_info = NULL;
 	conn->path_info = NULL;
 	conn->status_code = -1;
 	conn->status_code = -1;
+	conn->content_len = -1;
 	conn->is_chunked = 0;
 	conn->is_chunked = 0;
 	conn->must_close = 0;
 	conn->must_close = 0;
 	conn->request_len = 0;
 	conn->request_len = 0;
@@ -15332,7 +15332,6 @@ get_response(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *err)
 		conn->content_len = -1; /* unknown content length */
 		conn->content_len = -1; /* unknown content length */
 	}
 	}
 
 
-
 	conn->connection_type = 2; /* Valid response */
 	conn->connection_type = 2; /* Valid response */
 	return 1;
 	return 1;
 }
 }

+ 1 - 1
test/main.c

@@ -49,7 +49,7 @@ main(const int argc, char *argv[])
 	const char *const test_dir_arg = "--test-dir=";
 	const char *const test_dir_arg = "--test-dir=";
 	const size_t test_dir_arg_size = strlen(test_dir_arg);
 	const size_t test_dir_arg_size = strlen(test_dir_arg);
 
 
-	SRunner * srunner;
+	SRunner *srunner;
 	int number_run = 0;
 	int number_run = 0;
 	int number_failed = 0;
 	int number_failed = 0;
 
 

+ 1 - 0
test/public_server.c

@@ -871,6 +871,7 @@ request_test_handler(struct mg_connection *conn, void *cbdata)
 	return 1;
 	return 1;
 }
 }
 
 
+
 #ifdef USE_WEBSOCKET
 #ifdef USE_WEBSOCKET
 /****************************************************************************/
 /****************************************************************************/
 /* WEBSOCKET SERVER                                                         */
 /* WEBSOCKET SERVER                                                         */