Explorar o código

Rewrite request parsing (Step 25/?)

bel2125 %!s(int64=8) %!d(string=hai) anos
pai
achega
6e448f1392
Modificáronse 3 ficheiros con 17 adicións e 6 borrados
  1. 8 1
      src/civetweb.c
  2. 8 5
      test/private.c
  3. 1 0
      test/public_server.c

+ 8 - 1
src/civetweb.c

@@ -14667,15 +14667,22 @@ get_response(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *err)
 			*err = 411;
 			*err = 411;
 			return 0;
 			return 0;
 		}
 		}
-		/* Publish the content length back to the request info. */
+		/* Publish the content length back to the response info. */
+		conn->response_info.content_length = conn->content_len;
+
+		/* TODO: check if it is still used in response_info */
 		conn->request_info.content_length = conn->content_len;
 		conn->request_info.content_length = conn->content_len;
+
 	} else if ((cl = get_header(conn->response_info.http_headers,
 	} else if ((cl = get_header(conn->response_info.http_headers,
 	                            conn->response_info.num_headers,
 	                            conn->response_info.num_headers,
 	                            "Transfer-Encoding")) != NULL
 	                            "Transfer-Encoding")) != NULL
 	           && !mg_strcasecmp(cl, "chunked")) {
 	           && !mg_strcasecmp(cl, "chunked")) {
 		conn->is_chunked = 1;
 		conn->is_chunked = 1;
+	} else {
+		conn->content_len = -1;
 	}
 	}
 
 
+
 	conn->connection_type = 2; /* Valid response */
 	conn->connection_type = 2; /* Valid response */
 	return 1;
 	return 1;
 }
 }

+ 8 - 5
test/private.c

@@ -267,14 +267,17 @@ START_TEST(test_should_keep_alive)
 	ck_assert_int_eq(conn.request_info.num_headers, 1);
 	ck_assert_int_eq(conn.request_info.num_headers, 1);
 	ck_assert_int_eq(should_keep_alive(&conn), 1);
 	ck_assert_int_eq(should_keep_alive(&conn), 1);
 
 
-	/* No longer required. Server sets must_close if status is 401
+	conn.status_code = 200;
+	conn.must_close = 1;
+	ck_assert_int_eq(should_keep_alive(&conn), 0);
 
 
-	    conn.status_code = 401;
-	    ck_assert_int_eq(should_keep_alive(&conn), 0);
-	*/
+	conn.status_code = 200;
+	conn.must_close = 0;
+	ck_assert_int_eq(should_keep_alive(&conn), 1);
 
 
 	conn.status_code = 200;
 	conn.status_code = 200;
-	conn.must_close = 1;
+	conn.must_close = 0;
+	conn.connection_type = 0; /* invalid */
 	ck_assert_int_eq(should_keep_alive(&conn), 0);
 	ck_assert_int_eq(should_keep_alive(&conn), 0);
 }
 }
 END_TEST
 END_TEST

+ 1 - 0
test/public_server.c

@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdarg.h>
 #include <string.h>
 #include <string.h>
+#include <stdint.h>
 #include <time.h>
 #include <time.h>
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/stat.h>