Skip to content

Commit 36bf10e

Browse files
author
Soufiane Nouae
committed
last
1 parent d3b601f commit 36bf10e

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

CGI/cgi.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,11 @@ std::string run_cgi(request &r, Respond &res, std::vector<server> server)
123123
return res.get_response_status(res.get_status_code());
124124
}
125125
char buf[1];
126-
std::string content;
127126
int byt;
127+
std::string content;
128128
std::rewind(temp);
129-
while ((byt = read(fdtemp, buf, 1)) > 0){
129+
while ((byt = read(fdtemp, buf, 1)) > 0)
130130
content.append(buf, 1);
131-
}
132131
if (byt == -1)
133132
{
134133
res.set_status_code(500);

config/server.conf

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ server
44

55
host 127.0.0.1;
66
client_max_body_size 100;
7-
7+
server_name hhjdsghj dsfsdfda dfdsfsdf;
88

99
error_page 404 www/html/error_pages/404.html;
1010
error_page 403 www/html/error_pages/403.html;
@@ -24,11 +24,12 @@ server
2424
{
2525
root ./www/html/cgi_bin;
2626
allow_Methods GET;
27-
#index hello.html;
27+
allow_Methods POST;
28+
index hello.html;
2829
path_info .py /usr/bin/python3;
2930
path_info .php /php-cgi;
3031
# listen 8001;
31-
autoindex on;
32+
#autoindex on;
3233
}
3334

3435
location /red
@@ -45,11 +46,11 @@ server
4546

4647
location /upload{
4748
root ./www/html/upload;
48-
# index upload.html;
49+
index upload.html;
4950
allow_methods POST GET;
5051
upload on;
5152
upload_store ./www/html/upload;
52-
autoindex on;
53+
#autoindex on;
5354
}
5455

5556
location /getto {

prs_rsc/location.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ location::~location()
5555

5656
void location::fill_rest(server &s)
5757
{
58-
// if (_index.empty())
59-
// _index = s.get_index();
6058
if (!_client_max_body_size)
6159
_client_max_body_size = s.get_client_max_body_size();
6260
if (_root.empty())

prs_rsc/server.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,22 @@ server::server(Data_config data, bool check_location)
229229
if (key == "server_name" && check_location)
230230
{
231231
is_empty_value(value, line);
232-
if (ft_numbers_value(iss) || !isValidServerName(value))
232+
if (!isValidServerName(value))
233233
ft_error(line, "Error");
234234
std::vector<std::string>::iterator it = std::find(_server_name.begin(), _server_name.end(), value);
235235
if(it != _server_name.end())
236236
ft_error(line, "duplicate server_name");
237-
c_server_name++;
238237
_server_name.push_back(value);
238+
while (iss >> value)
239+
{
240+
if (!isValidServerName(value))
241+
ft_error(line, "Error");
242+
std::vector<std::string>::iterator it = std::find(_server_name.begin(), _server_name.end(), value);
243+
if(it != _server_name.end())
244+
ft_error(line, "duplicate server_name");
245+
_server_name.push_back(value);
246+
}
247+
c_server_name++;
239248
}
240249
else if (key == "host" && check_location)
241250
{

prs_rsc/server_utils.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ std::vector<server> ft_fill_servers(char **av, int ac)
4545
int c = 0;
4646
int flag = 0;
4747
int kws = 0;
48-
size_t i = 0, j = 0;
48+
size_t i = 0, is_server = 0;
4949
if (ac == 2)
5050
config_file = av[1];
5151
else
@@ -65,7 +65,7 @@ std::vector<server> ft_fill_servers(char **av, int ac)
6565
c -= search_char(line, '}');
6666
if (is_world(&line[i], "server"))
6767
{
68-
j = 1;
68+
is_server = 1;
6969
if (!search_char(line, '{'))
7070
{
7171
while (!file.eof())
@@ -93,7 +93,7 @@ std::vector<server> ft_fill_servers(char **av, int ac)
9393
}
9494
if (is_world(&line[i], "location"))
9595
{
96-
if(!j)
96+
if(!is_server)
9797
{
9898
std::cerr << "error something outside of server\n";
9999
exit (1);
@@ -124,7 +124,7 @@ std::vector<server> ft_fill_servers(char **av, int ac)
124124
}
125125
}
126126
}
127-
else if (!j)
127+
else if (!is_server)
128128
{
129129
if (!line.empty())
130130
{
@@ -134,9 +134,9 @@ std::vector<server> ft_fill_servers(char **av, int ac)
134134
}
135135
else if (!line.empty())
136136
data.data_server += line + "\n";
137-
if (!c && j)
137+
if (!c && is_server)
138138
{
139-
j = 0;
139+
is_server = 0;
140140
kws = 0;
141141
v.push_back(data);
142142
data.data_server.clear();

www/html/upload/upload.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ <h1>File Uploader</h1>
9393
<p>Select files to upload</p>
9494
</header>
9595
<main>
96-
<form action="http://localhost:8001/upload/success.html" method="post" enctype="multipart/form-data">
96+
<form action="http://localhost:8002/upload/success.html" method="post" enctype="multipart/form-data">
9797
<div class="form-group">
9898
<label for="file1">File 1</label>
9999
<input type="file" name="file1" id="file1" accept=".jpg, .jpeg, .png, .pdf, .mp4" required>

0 commit comments

Comments
 (0)