6
6
/* By: aoumad <[email protected] > +#+ +:+ +#+ */
7
7
/* +#+#+#+#+#+ +#+ */
8
8
/* Created: 2023/04/11 02:14:39 by aoumad #+# #+# */
9
- /* Updated: 2023/05/23 14:54:00 by aoumad ### ########.fr */
9
+ /* Updated: 2023/05/24 01:02:19 by aoumad ### ########.fr */
10
10
/* */
11
11
/* ************************************************************************** */
12
12
@@ -202,6 +202,7 @@ void Respond::ft_handle_error(int error_code)
202
202
203
203
void Respond::ft_show_autoindex (std::vector<server> server)
204
204
{
205
+ std::cout << " rooted path: " << _rooted_path << std::endl;
205
206
std::string index_html = " <!DOCTYPE html>\n <html>\n <head>\n " ;
206
207
index_html += " <meta charset=\" UTF-8\" >\n " ;
207
208
index_html += " <title>Index of " + _rooted_path + " </title>\n " ;
@@ -228,18 +229,18 @@ void Respond::ft_show_autoindex(std::vector<server> server)
228
229
{
229
230
if (entry->d_name [0 ] != ' .' )
230
231
{
231
- file_name = std::string (entry->d_name );
232
+ file_name = std::string (entry->d_name ); // cgi_bin
232
233
std::string file_path;
233
234
if (_path_found[_path_found.size () - 1 ] == ' /' )
234
- file_path = _path_found + file_name;
235
+ file_path = _path_found + file_name; // /cgi_bin
235
236
else
236
237
file_path = _path_found + " /" + file_name;
238
+ // std::cout << "file path: " << file_path << std::endl;
237
239
std::string match_path;
238
240
if (_rooted_path[_rooted_path.size () - 1 ] == ' /' )
239
- match_path = _rooted_path + file_name;
241
+ match_path = _rooted_path + file_name; // www/html/cgi_bin
240
242
else
241
243
match_path = _rooted_path + " /" + file_name;
242
-
243
244
if (stat (match_path.c_str (), &file_stat) < 0 )
244
245
{
245
246
handle_error_response (server, 403 );
@@ -252,7 +253,6 @@ void Respond::ft_show_autoindex(std::vector<server> server)
252
253
std::strftime (buffer, sizeof (buffer), " %Y-%m-%d %H:%M:%S" , timeInfo);
253
254
std::string fileTime (buffer);
254
255
255
- // Now you can use 'fileTime' in your HTML code
256
256
index_html += " <p><a href=\" http://" + r.get_header (" Host" ) + file_path + " \" ><b><i><font size=\" 5\" >" + file_name + " </font></i></b></a>" ;
257
257
index_html += " \t\t <b><i><font size=\" 5\" >" + file_size + " \t\t " + fileTime + " </font></i></b></p>\n " ;
258
258
}
@@ -273,9 +273,12 @@ void Respond::handle_error_response(std::vector<server> server, int error_cod
273
273
file.open (error_path.c_str ());
274
274
if (file.is_open ())
275
275
{
276
+ set_status_code (error_code);
277
+ set_status_message (get_response_status (error_code));
276
278
_response_body = std::string ((std::istreambuf_iterator<char >(file)), std::istreambuf_iterator<char >());
277
279
set_header (" Content-Type" , get_mime_type (" html" ));
278
280
set_header (" Content-Length" , std::to_string (_response_body.length ()));
281
+ set_date ();
279
282
set_cache_control (" no cache" );
280
283
}
281
284
// file.close();
@@ -289,6 +292,7 @@ void Respond::handle_error_response(std::vector<server> server, int error_cod
289
292
set_date ();
290
293
_response_body = " <html><head><title>" + std::to_string (error_code) + " " + _status_message + " </title></head><body><h1>" + std::to_string (error_code) + " " + _status_message + " </h1><p>You don't have permission to access " + r.get_uri () + " on this server.</p></body></html>" ;
291
294
set_header (" Content-Length" , std::to_string (_response_body.length ()));
295
+ set_date ();
292
296
set_cache_control (" no cache" );
293
297
}
294
298
}
0 commit comments