@@ -101,31 +101,31 @@ http_response::http_response(http_request *req,struct pollfd *fd,std::string &ho
101
101
content_remaining = 0 ;
102
102
request = req;
103
103
void (http_response::*state_handlers[3 ])() = {&http_response::GET_check_state,&http_response::POST_check_state,&http_response::DELETE_check_state};
104
- conf = get_config (host,port,request->get_path (),request->get_header (" HOST" ));
105
- for (int i = 0 ; i < conf. methods .size (); i++) {
106
- std::cout << " method: [" << conf. methods [i] << " ]\n " ;
104
+ conf = & get_config (host,port,request->get_path (),request->get_header (" HOST" ));
105
+ for (int i = 0 ; i < conf-> methods .size (); i++) {
106
+ std::cout << " method: [" << conf-> methods [i] << " ]\n " ;
107
107
}
108
- std::cout << " root: [" << conf. root << " ]\n " ;
109
- for (int i = 0 ; i < conf. index .size (); i++) {
110
- std::cout << " index: [" << conf. index [i] << " ]\n " ;
108
+ std::cout << " root: [" << conf-> root << " ]\n " ;
109
+ for (int i = 0 ; i < conf-> index .size (); i++) {
110
+ std::cout << " index: [" << conf-> index [i] << " ]\n " ;
111
111
}
112
- std::cout << " autoindex: [" << conf. autoindex << " ]\n " ;
113
- std::cout << " upload_pass: [" << conf. upload_pass << " ]\n " ;
114
- for (int i = 0 ; i < conf. cgi_pass .size (); i++) {
115
- std::cout << " cgi_param: [" << conf. cgi_pass [i].cgi_param << " ]\n " ;
116
- std::cout << " cgi_pass: [" << conf. cgi_pass [i].cgi_pass << " ]\n " ;
112
+ std::cout << " autoindex: [" << conf-> autoindex << " ]\n " ;
113
+ std::cout << " upload_pass: [" << conf-> upload_pass << " ]\n " ;
114
+ for (int i = 0 ; i < conf-> cgi_pass .size (); i++) {
115
+ std::cout << " cgi_param: [" << conf-> cgi_pass [i].cgi_param << " ]\n " ;
116
+ std::cout << " cgi_pass: [" << conf-> cgi_pass [i].cgi_pass << " ]\n " ;
117
117
}
118
- std::cout << " mcbs: [" << conf. client_max_body_size << " ]\n " ;
119
- for (std::map<int , std::string>::iterator it = conf. err_pages .begin (); it != conf. err_pages .end (); it++)
118
+ std::cout << " mcbs: [" << conf-> client_max_body_size << " ]\n " ;
119
+ for (std::map<int , std::string>::iterator it = conf-> err_pages .begin (); it != conf-> err_pages .end (); it++)
120
120
{
121
121
std::cout << " err_page: [" << it->first << " -" << it->second << " ]\n " ;
122
122
}
123
- std::cout << " ret_value: [" << conf. return_value << " ]\n " ;
123
+ std::cout << " ret_value: [" << conf-> return_value << " ]\n " ;
124
124
125
125
126
126
std::cerr <<" [" << host << " ] [" + port + " ] [" + request->get_path () + " ] [" + request->get_header (" HOST" ) + " ]\n " ;
127
127
std::cerr <<" THE '/' is added to the root end, do not add it again!\n " ;
128
- std::cout << " ------------------ " << conf. root << " ----" << std::endl;
128
+ std::cout << " ------------------ " << conf-> root << " ----" << std::endl;
129
129
std::map<std::string,int > met_map;
130
130
met_map[" GET" ] = GET;
131
131
met_map[" POST" ] = POST;
@@ -137,10 +137,10 @@ http_response::http_response(http_request *req,struct pollfd *fd,std::string &ho
137
137
{
138
138
if (met_map.find (request->get_method ()) == met_map.end ())
139
139
throw NOT_IMPLEMENTED;
140
- if (conf. methods [0 ] != " ALL" && std::find (conf. methods .begin (),conf. methods .end (),request->get_method ()) == conf. methods .end ())
140
+ if (conf-> methods [0 ] != " ALL" && std::find (conf-> methods .begin (),conf-> methods .end (),request->get_method ()) == conf-> methods .end ())
141
141
throw NOT_ALLOWED;
142
142
type = met_map[request->get_method ()];
143
- if (conf. return_value != " " )
143
+ if (conf-> return_value != " " )
144
144
throw 301 ;
145
145
(this ->*state_handlers[type])();
146
146
if (type == CGI && request->get_method () == " GET" )
@@ -227,21 +227,21 @@ void http_response::ERROR_handler(int x)
227
227
client->events = POLLOUT;
228
228
if (x == END)
229
229
throw x;
230
- if (conf. err_pages [x] != " " )
230
+ if (conf-> err_pages [x] != " " )
231
231
{
232
- file.open (conf. err_pages [x]);
232
+ file.open (conf-> err_pages [x]);
233
233
if (file.good ())
234
234
{
235
- conf. root = conf. err_pages [x];
236
- conf. err_pages [x] = " " ;
235
+ conf-> root = conf-> err_pages [x];
236
+ conf-> err_pages [x] = " " ;
237
237
type = GET;
238
238
state = FILE;
239
239
file.close ();
240
240
return ;
241
241
}
242
242
else if (file.is_open ())
243
243
file.close ();
244
- conf. err_pages [x] = " " ;
244
+ conf-> err_pages [x] = " " ;
245
245
}
246
246
error_pages_map errors;
247
247
body += errors.get_error (x);
@@ -250,7 +250,7 @@ void http_response::ERROR_handler(int x)
250
250
std::cout << " excesss = " << body << std::endl;
251
251
headers[" Content-Type" ] = content_type[" html" ];
252
252
if (x == 301 )
253
- headers[" LOCATION" ] = conf. return_value ;
253
+ headers[" LOCATION" ] = conf-> return_value ;
254
254
res_header = " HTTP/1.1 " + int_to_string (x) + " " + errors.get_message (x) + " \n " ;
255
255
for (std::map<std::string,std::string>::iterator it = headers.begin (); it != headers.end (); it++)
256
256
res_header += (*it).first + " :" + (*it).second + " \n " ;
@@ -261,9 +261,9 @@ void http_response::ERROR_handler(int x)
261
261
262
262
int http_response::check_cgi (std::string &file)
263
263
{
264
- for (int c = 0 ; c < conf. cgi_pass .size ();c++)
264
+ for (int c = 0 ; c < conf-> cgi_pass .size ();c++)
265
265
{
266
- if (extention (file) == conf. cgi_pass [c].cgi_pass )
266
+ if (extention (file) == conf-> cgi_pass [c].cgi_pass )
267
267
return 1 ;
268
268
}
269
269
return 0 ;
0 commit comments