Skip to content

Commit 56b9080

Browse files
author
Younes Ismaili
committed
webserv is finished
1 parent bae547a commit 56b9080

File tree

4 files changed

+64
-58
lines changed

4 files changed

+64
-58
lines changed

config/server.conf

+54-53
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
server
22
{
3-
listen 8002;
3+
listen 80;
44

55
host 127.0.0.1;
66
client_max_body_size 100;
@@ -60,67 +60,68 @@ server
6060
autoindex on;
6161
}
6262
}
63-
# server
64-
# {
65-
# listen 8002;
6663

67-
# host 127.0.0.1;
68-
# client_max_body_size 10000000;
69-
# root ./www/html;
70-
# server_name localhostp;
71-
# error_page 404 www/html/error_pages/404.html;
72-
# error_page 403 www/html/error_pages/403.html;
73-
# error_page 409 www/html/error_pages/409.html;
74-
# error_page 400 www/html/error_pages/400.html;
75-
# error_page 405 www/html/error_pages/405.html;
76-
# error_page 413 www/html/error_pages/413.html;
77-
# error_page 500 www/html/error_pages/500.html;
64+
server
65+
{
66+
listen 80;
7867

79-
# index index.html;
68+
host 127.0.0.1;
69+
client_max_body_size 10000000;
70+
root ./www/html;
71+
server_name localhostp;
72+
error_page 404 www/html/error_pages/404.html;
73+
error_page 403 www/html/error_pages/403.html;
74+
error_page 409 www/html/error_pages/409.html;
75+
error_page 400 www/html/error_pages/400.html;
76+
error_page 405 www/html/error_pages/405.html;
77+
error_page 413 www/html/error_pages/413.html;
78+
error_page 500 www/html/error_pages/500.html;
79+
80+
index index.html;
8081

81-
# location / {
82-
# autoindex on;
83-
# }
82+
location / {
83+
autoindex on;
84+
}
8485

85-
# location /cgi_bin
86-
# {
86+
location /cgi_bin
87+
{
8788

88-
# root ./www/html;
89-
# allow_Methods GET POST;
90-
# index hello.html;
91-
# path_info .py /usr/bin/python3;
92-
# path_info .php /php-cgi;
93-
# #listen 8001;
94-
# #autoindex on;
95-
# }
89+
root ./www/html;
90+
allow_Methods GET POST;
91+
index hello.html;
92+
path_info .py /usr/bin/python3;
93+
path_info .php /php-cgi;
94+
#listen 8001;
95+
#autoindex on;
96+
}
9697

97-
# location /red
98-
# {
99-
# return 301 https://www.youtube.com/watch?v=_Nbm2yn8WA8&t=30s;
100-
# }
98+
location /red
99+
{
100+
return 301 https://www.youtube.com/watch?v=_Nbm2yn8WA8&t=30s;
101+
}
101102

102-
# location /delete {
103-
# root ./www/html/delete;
104-
# allow_methods DELETE;
105-
# index todelete;
106-
# path_info .py /usr/bin/python3;
107-
# }
103+
location /delete {
104+
root ./www/html/delete;
105+
allow_methods DELETE;
106+
index todelete;
107+
path_info .py /usr/bin/python3;
108+
}
108109

109-
# location /upload{
110-
# root ./www/html/upload;
111-
# index upload.html;
112-
# allow_methods POST GET;
113-
# upload on;
114-
# upload_store /upload;
115-
# }
110+
location /upload{
111+
root ./www/html/upload;
112+
index upload.html;
113+
allow_methods POST GET;
114+
upload on;
115+
upload_store /upload;
116+
}
116117

117-
# location /getto {
118-
# root ./www/html/upload;
119-
# index vid.mp4;
120-
# allow_methods GET;
121-
# autoindex off;
122-
# }
123-
# }
118+
location /getto {
119+
root ./www/html/upload;
120+
index vid.mp4;
121+
allow_methods GET;
122+
autoindex off;
123+
}
124+
}
124125

125126
# server
126127
# {

include/sockets.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: yismaili <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/03/27 15:29:15 by yismaili #+# #+# */
9-
/* Updated: 2023/05/22 22:13:50 by yismaili ### ########.fr */
9+
/* Updated: 2023/05/24 14:46:10 by yismaili ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

server/http_server.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: yismaili <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/04/04 18:41:23 by yismaili #+# #+# */
9-
/* Updated: 2023/05/23 21:02:41 by yismaili ### ########.fr */
9+
/* Updated: 2023/05/24 14:55:56 by yismaili ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -137,7 +137,6 @@ namespace http{
137137
clients.push_back(server_pollfd);
138138
it++;
139139
}
140-
141140
while (true)
142141
{
143142
i = 0;

server/sockets.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: yismaili <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/04/04 18:41:42 by yismaili #+# #+# */
9-
/* Updated: 2023/05/22 22:48:44 by yismaili ### ########.fr */
9+
/* Updated: 2023/05/24 14:56:46 by yismaili ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -96,6 +96,7 @@ namespace http{
9696
bool sockets::start_server()
9797
{
9898
int optval;
99+
static int check_port = 0;
99100

100101
optval = 1; //enabling the SO_REUSEADDR socket option.
101102
// Creates a TCP socket
@@ -118,11 +119,16 @@ namespace http{
118119
fcntl(sockfd, F_SETFL, O_NONBLOCK);
119120

120121
//bind a socket with a specific address and port number
121-
if (bind(sockfd, result->ai_addr, result->ai_addrlen) == 0)
122+
int ret_bind = bind(sockfd, result->ai_addr, result->ai_addrlen);
123+
if (ret_bind == 0)
122124
{
123125
// F_SETFL: This flag indicates that we want to set the file status flags.
126+
check_port++;
124127
std::cout << "\n\033[32mLISTENING ON ["<<port<<"]...\033[0m\n";
125128
}
129+
else if (ret_bind == -1 && check_port == 0){
130+
std::cout << "\033[31mthis ["<<port<<"] port is used\033[0m\n";
131+
}
126132
// Set socket to listen
127133
if (listen(sockfd, SOMAXCONN) < 0){
128134
// The backlog argument defines the maximum length to which the queue of pending connections for sockfd may grow

0 commit comments

Comments
 (0)