Skip to content

Commit 07c255c

Browse files
author
Younes Ismaili
committed
merge with request response
2 parents 2db981a + 4510f95 commit 07c255c

File tree

9 files changed

+139
-128
lines changed

9 files changed

+139
-128
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
NAME = webserv
22
CC = c++
3-
CFLAGS = -Wall -Wextra -Werror -std=c++98
3+
CFLAGS = -Wall -Wextra -Werror -std=c++98 -g -fsanitize=address
44
SRCS = prs_rsc/main.cpp prs_rsc/server.cpp prs_rsc/location.cpp prs_rsc/server_utils.cpp \
55
request/request.cpp request/request_utils.cpp respond/respond.cpp respond/respond_root.cpp respond/pairs_def.cpp respond/method_utils.cpp \
66
respond/method_handling.cpp CGI/cgi.cpp server/sockets.cpp server/http_server.cpp

prs_rsc/server.conf

+16-49
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,50 @@
1-
# server {
2-
# listen 8004;
3-
# listen 8002;
4-
# listen 8003;
5-
# server_name localhost;
6-
# host 127.0.0.1;
7-
# client_max_body_size 200000;
8-
# error_page 404 error_pages/404.html;
9-
# error_page 500 error_pages/500.html;
10-
# autoindex on;
11-
12-
# location /favicon.ico
13-
# {
14-
# #allow_methods GET POST DELETE;
15-
# root ./web_pages/favicon.ico;
16-
# return 301 https://www.example.com$request_uri;
17-
# }
18-
19-
# location /favicon.php
20-
# {
21-
# allow_methods GET POST DELETE;
22-
# }
23-
# location /favicon.php
24-
# {
25-
# allow_methods GET POST DELETE;
26-
# }
27-
# }
28-
29-
30-
31-
321
server {
33-
# default server;
342

353
listen 8001;
364

375

386
host 127.0.0.1;
397
client_max_body_size 10000000;
40-
root ./www/html/ffuyu;
8+
root ./www/html;
419
error_page 404 www/html/error_pages/404.html;
4210
error_page 500 www/html/error_pages/500.html;
4311

44-
#allow_methods GET POST DELETE;
4512
autoindex on;
46-
index index.html ;
47-
#meme_types ./configs/types.conf;
13+
index index.html;
4814

4915

16+
location /favicon.ico {
17+
allow_methods GET POST DELETE;
18+
root ./www/html/favicon.ico;
19+
}
20+
5021
location / {
5122
allow_methods GET POST DELETE;
5223
root ./www/html/favicon.ico;
53-
autoindex on;
5424
}
5525

56-
location /cgi_bin {
26+
location /cgi_bin
27+
{
5728
root ./www/html/cgi_bin;
5829
allow_methods GET POST;
5930
index hello.html;
6031
path_info .py /usr/bin/python3;
6132
path_info .php ./php-cgi;
6233
}
6334

64-
location /red {
35+
location /red
36+
{
6537
return 301 https://www.youtube.com/watch?v=_Nbm2yn8WA8&t=30s;
6638
}
6739

68-
location /delete
69-
{
40+
location /delete {
7041
root ./www/html/delete;
7142
allow_methods DELETE;
7243
index todelete;
7344
path_info .py /usr/bin/python3;
7445
}
7546

76-
location /upload
77-
{
47+
location /upload{
7848
root ./www/html/upload;
7949
index upload.html;
8050
allow_methods POST GET;
@@ -84,23 +54,20 @@ server {
8454

8555
server {
8656
listen 8000;
87-
root ./www/html/delete;
57+
8858
host 127.0.0.1;
8959

60+
server_name mazhari;
9061
client_max_body_size 26336;
91-
#allow_methods GET POST DELETE;
9262
autoindex on;
9363
index server2.html;
94-
#meme_types ./configs/types.conf;
9564
}
9665

9766
server {
9867
listen 8003;
9968

10069
host 127.0.0.1;
10170
client_max_body_size 26000;
102-
#allow_methods GET POST DELETE;
10371
autoindex on;
10472
index server3.html;
105-
#meme_types ./configs/types.conf;
106-
}
73+
}

request/request.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212

1313
#include "request.hpp"
1414

15-
request::request()
15+
request::request() : _method(""), _uri(""), _version(""),
16+
_body(""), _port(80), _query("")
1617
{
1718
return ;
1819
}
1920

20-
request::request(std::string request)
21+
request::request(std::string request) : _method(""), _uri(""), _version(""),
22+
_body(""), _port(80), _query("")
2123
{
2224
this->parse_request(request);
2325
return ;
@@ -43,6 +45,8 @@ request &request::operator=(const request &src)
4345
this->_version = src._version;
4446
this->_headers = src._headers;
4547
this->_body = src._body;
48+
this->_port = src._port;
49+
this->_query = src._query;
4650
}
4751
return (*this);
4852
}

respond/method_handling.cpp

+22-9
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,41 @@
66
/* By: aoumad <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/04/09 17:52:50 by aoumad #+# #+# */
9-
/* Updated: 2023/05/08 18:04:33 by aoumad ### ########.fr */
9+
/* Updated: 2023/05/09 17:50:06 by aoumad ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "respond.hpp"
1414

1515
void Respond::handle_get_response(std::vector<server> servers)
1616
{
17-
1817
// step 2: check if it's a CGI or not (like if `index` of the configuration file has .py or .php...etc)
18+
if (_is_cgi == true)
19+
{
20+
run_cgi(r, *this);
21+
return ;
22+
}
1923
// step 3: check if it's a file or not
2024
if (ft_check_file() == true)
25+
{
2126
ft_handle_file();
22-
else
23-
handle_error_response(404);
27+
return ;
28+
}
29+
// else
30+
// {
31+
// std::cout << "___--_------__------_-_-_--_-__-_-_-_-HEREEEEE_--_-_-_--_-_-_-_-" << std::endl;
32+
// handle_error_response(404);
33+
// return ;
34+
// }
2435
// step 4 : check the index in the configuration file and render it
25-
ft_handle_index(servers);
26-
36+
if (ft_handle_index(servers))
37+
return ;
2738
// step 5: check if the autoindex if on or off
28-
ft_handle_autoindex(servers);
29-
30-
// ft_handle_error(404);
39+
if (ft_handle_autoindex(servers))
40+
{
41+
handle_error_response(403);
42+
return ;
43+
}
3144

3245
}
3346

0 commit comments

Comments
 (0)