@@ -8,9 +8,9 @@ static const char *user_agent_hdr = "User-Agent: Mozilla/5.0 (X11; Linux x86_64;
8
8
/* Proxy/client and proxy/server functions prototypes */
9
9
static void serve_client (int connfd , cache_line_t * cache );
10
10
static void service_from_cache (int connfd , cache_line_t * cache , size_t matched_line_idx );
11
- static void service_from_server (int connfd , URL_INFO url_info , char * parsed_request ,
11
+ static void service_from_server (int connfd , URL_INFO * url_info , char * parsed_request ,
12
12
cache_line_t * cache , size_t HTTP_request_hash );
13
- static int connect_server (URL_INFO url_info , char * parsed_request , int connfd , char * cache_buf );
13
+ static int connect_server (URL_INFO * url_info , char * parsed_request , int connfd , char * cache_buf );
14
14
15
15
/* Manipulating HTTP requests functions prototypes */
16
16
static int read_HTTP_request (int connfd , URL_INFO * url_infop , char * headers );
@@ -49,13 +49,13 @@ void *thread(void *vargp)
49
49
*/
50
50
static void serve_client (int connfd , cache_line_t * cache )
51
51
{
52
- URL_INFO url_info ;
52
+ URL_INFO * url_info = Malloc ( 4 * sizeof ( char * )) ;
53
53
char parsed_request [MAXLINE ];
54
54
size_t HTTP_request_hash ;
55
55
int matched_line_idx ;
56
56
57
57
/* Read request line and headers from the client */
58
- if (read_HTTP_request (connfd , & url_info , parsed_request ) < 0 )
58
+ if (read_HTTP_request (connfd , url_info , parsed_request ) < 0 )
59
59
return ;
60
60
61
61
HTTP_request_hash = hash (parsed_request );
@@ -82,6 +82,7 @@ static void serve_client(int connfd, cache_line_t *cache)
82
82
/* Forward request on to the server */
83
83
connect_server (url_info , parsed_request , connfd , cache_buf );
84
84
#endif
85
+ Free (url_info );
85
86
}
86
87
87
88
/*
@@ -90,16 +91,16 @@ static void serve_client(int connfd, cache_line_t *cache)
90
91
* response and forward it to client. if proxy has a cache, copy
91
92
* the response content to cache_buf to save it in the cache.
92
93
*/
93
- static int connect_server (URL_INFO url_info , char * parsed_request , int connfd , char * cache_buf )
94
+ static int connect_server (URL_INFO * url_info , char * parsed_request , int connfd , char * cache_buf )
94
95
{
95
96
int clientfd ;
96
97
int total = 0 ;
97
98
char * host , * port , buf [MAXBUF ];
98
99
rio_t rio ;
99
100
ssize_t nread ;
100
101
101
- host = url_info . host ;
102
- port = url_info . port ;
102
+ host = url_info -> host ;
103
+ port = url_info -> port ;
103
104
if (!host || !port ) return 0 ;
104
105
if ((clientfd = open_clientfd (host , port )) < 0 ) {
105
106
char msg [MAXLINE ];
@@ -154,14 +155,13 @@ static int read_request_line(rio_t *rp, URL_INFO *url_infop, char *parsed_reques
154
155
return -1 ;
155
156
}
156
157
// Check HTTP version
157
- if (strcmp ("HTTP/1.0" , version ) && strcmp ("HTTP/1.1" , version )) {
158
+ if (strcasecmp ("HTTP/1.0" , version ) && strcasecmp ("HTTP/1.1" , version )) {
158
159
clienterror (rp -> rio_fd , version , "400" , "Bad request" ,
159
160
"Invalid HTTP version" );
160
161
return -1 ;
161
162
} else {
162
163
strcpy (version , "HTTP/1.0" );
163
164
}
164
-
165
165
parse_url (url_infop , url );
166
166
if (!url_infop ) {
167
167
clienterror (rp -> rio_fd , url , "400" , "Bad request" ,
@@ -319,7 +319,7 @@ static void service_from_cache(int connfd, cache_line_t *cache, size_t matched_l
319
319
* save object in the cache to read it quickly in case of
320
320
* same future requests without connecting the server.
321
321
*/
322
- static void service_from_server (int connfd , URL_INFO url_info , char * parsed_request ,
322
+ static void service_from_server (int connfd , URL_INFO * url_info , char * parsed_request ,
323
323
cache_line_t * cache , size_t HTTP_request_hash )
324
324
{
325
325
char cache_buf [MAX_OBJECT_SIZE ];
0 commit comments