@@ -39,60 +39,13 @@ void forward_response(const char *key, int infd, int outfd)
39
39
struct Bytes response ;
40
40
bytes_malloc (& response );
41
41
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
-
67
42
int num_bytes ;
68
43
while ((num_bytes = rio_readnb_ww (& rio , buf , MAXLINE )) > 0 ) {
69
44
bytes_appendn (& response , buf , num_bytes );
70
45
}
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 ;
94
48
}
95
-
96
49
97
50
#ifdef DEBUG
98
51
fprintf (stderr , "response length: %zu\n" , bytes_length (response ));
0 commit comments