Skip to content

Commit 48dc9de

Browse files
committed
update forward response
1 parent a9cfe41 commit 48dc9de

File tree

1 file changed

+2
-49
lines changed

1 file changed

+2
-49
lines changed

proxylab-handout/proxy.c

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -39,60 +39,13 @@ void forward_response(const char *key, int infd, int outfd)
3939
struct Bytes response;
4040
bytes_malloc(&response);
4141

42-
if (!rio_readlineb_ww(&rio, buf, MAXLINE)) {
43-
// goto is used here to makes sure that
44-
// the bytes are freed.
45-
goto FORWARD_RESPONSE_RETURN;
46-
}
47-
48-
bytes_append(&response, buf);
49-
50-
if (!rio_readlineb_ww(&rio, buf, MAXLINE)) {
51-
goto FORWARD_RESPONSE_RETURN;
52-
}
53-
char header_name[MAXLINE], header_value[MAXLINE];
54-
int content_length = 0;
55-
while (strcmp(buf, "\r\n")) {
56-
parse_header(buf, header_name, header_value);
57-
if (strcasecmp(header_name, "Content-length") == 0) {
58-
content_length = atoi(header_value);
59-
}
60-
bytes_append(&response, buf);
61-
if (!rio_readlineb_ww(&rio, buf, MAXLINE) < 0) {
62-
goto FORWARD_RESPONSE_RETURN;
63-
}
64-
}
65-
bytes_append(&response, buf);
66-
6742
int num_bytes;
6843
while ((num_bytes=rio_readnb_ww(&rio, buf, MAXLINE)) > 0) {
6944
bytes_appendn(&response, buf, num_bytes);
7045
}
71-
72-
#if 0
73-
if (content_length == 0) {
74-
75-
} else {
76-
#ifdef DEBUG
77-
fprintf(stderr, "Content-length: %d\n", content_length);
78-
#endif
79-
// read content
80-
char *content_buf = (char *)malloc((content_length+1)*sizeof(char));
81-
if (content_buf == NULL) {
82-
fprintf(stderr, "malloc failed\n");
83-
goto FORWARD_RESPONSE_RETURN;
84-
}
85-
if (!rio_readnb_ww(&rio, content_buf, content_length)) {
86-
goto FORWARD_RESPONSE_RETURN;
87-
}
88-
bytes_appendn(&response, content_buf, (size_t)content_length);
89-
free(content_buf);
90-
}
91-
#endif
92-
if (rio_readlineb_ww(&rio, buf, MAXLINE) != 0) {
93-
goto FORWARD_RESPONSE_RETURN;
46+
if (num_bytes < 0) {
47+
return ;
9448
}
95-
9649

9750
#ifdef DEBUG
9851
fprintf(stderr, "response length: %zu\n", bytes_length(response));

0 commit comments

Comments
 (0)