Skip to content

Commit a9cfe41

Browse files
committed
read content without relying on content length
1 parent e505523 commit a9cfe41

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

proxylab-handout/proxy.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ void forward_response(const char *key, int infd, int outfd)
6464
}
6565
bytes_append(&response, buf);
6666

67+
int num_bytes;
68+
while ((num_bytes=rio_readnb_ww(&rio, buf, MAXLINE)) > 0) {
69+
bytes_appendn(&response, buf, num_bytes);
70+
}
71+
72+
#if 0
6773
if (content_length == 0) {
68-
// TODO: error handling
69-
fprintf(stderr, "Content-length is 0\n");
70-
goto FORWARD_RESPONSE_RETURN;
74+
7175
} else {
7276
#ifdef DEBUG
7377
fprintf(stderr, "Content-length: %d\n", content_length);
@@ -84,6 +88,7 @@ void forward_response(const char *key, int infd, int outfd)
8488
bytes_appendn(&response, content_buf, (size_t)content_length);
8589
free(content_buf);
8690
}
91+
#endif
8792
if (rio_readlineb_ww(&rio, buf, MAXLINE) != 0) {
8893
goto FORWARD_RESPONSE_RETURN;
8994
}

0 commit comments

Comments
 (0)