diff --git a/42.config b/42.config new file mode 100644 index 0000000..072d955 --- /dev/null +++ b/42.config @@ -0,0 +1,23 @@ + +server { + + + server_name server1; + listen 0.0.0.0:4040; + client_body_limit 1000; + + index youpi.bla; # this is another comment + + root ./YoupiBanane/; + + error_page 404 ./www/error_pages/error_404.html; + + location / { + allow_methods GET; + } + + location /directory { + index youpi.bad_extention; + } + +} diff --git a/Tester/test2.config b/Tester/test2.config index dc39e1a..a9156a8 100644 --- a/Tester/test2.config +++ b/Tester/test2.config @@ -5,7 +5,7 @@ server { server_name server1; - listen 0.0.0.0:4040; + listen 0.0.0.0:8080; client_body_limit 1; # Max == 18446744073709551615 / 1024 == 18014398509481984 diff --git a/Tester/test3.config b/Tester/test3.config new file mode 100644 index 0000000..dcc8b47 --- /dev/null +++ b/Tester/test3.config @@ -0,0 +1,98 @@ + +server { + +# this is a comment + + server_name server1; + + listen 8080; +# listen 70000; + +# client_body_limit asdfa; + client_body_limit 1000; + # Max == 18446744073709551615 / 1024 == 18014398509481984 + + index index.html; # this is another comment + #index mdr.html; # this is another comment + + root ./Tester/www/; + + error_page 404 ./Tester/www/error_pages/error_404.html; + + + + location / { + allow_methods GET; + root ./Tester/www/; + } + + location /srcs/cgi-bin/ { + root ./srcs/cgi-bin/; + allow_methods POST; + cgi_ext php; + } + + location /list { + autoindex on; + } + + location /cgi-bin { + root ./srcs/cgi-bin/; + cgi_ext out php sh; + } + + location /upload { + allow_methods POST; + autoindex on; + upload_dir ./Tester/www/user_files/; + # root doesn’t matter if used only with POST and no CGI + } + + location /the_dump { + allow_methods GET DELETE; + root ./Tester/www/user_files; + autoindex on; + } + + location /redirect { + redirect 307 https://fr.wikipedia.org/wiki/Ketchup; +# redirect 307 https://www.youtube.com/watch?v=rG6b8gjMEkw; + } + + location /test { + index index1.html subdex.html; + root ./Tester/www/test/; + } + + location /stylesheet { + root ./stylesheet/; + } + + location /test/index1.html { + root ./Tester/www/test/index1.html; + index index1.html subdex.html; + } + + location /hilarious_404/ { + redirect 301 https://berniesanders.com/404/; + } + + location /test/something.html { + # allow_methods DELETE; + root ./Tester/www/test/something.html; + } + + location /test/test_deeper/ { +# allow_methods + root ./Tester/www/test/test_deeper/; + } + + location /test/test_deeper/super_deep { + root ./Tester/www/test/test_deeper/super_deep/; + } + +# location /test/test_deeper/something.html { +# allow_methods DELETE; +# } + +} diff --git a/Tester/test_body.sh b/Tester/test_body.sh index 4754772..fd0656d 100644 --- a/Tester/test_body.sh +++ b/Tester/test_body.sh @@ -3,7 +3,7 @@ test_name="Body Test" config_file="./Tester/test2.config" -port=4040 +port=8080 host="localhost" #paths=("/" "/test" "/test/" "/list" "list" "/wrong") # you can add many diff --git a/Tester/test_port.sh b/Tester/test_port.sh new file mode 100644 index 0000000..27c83cf --- /dev/null +++ b/Tester/test_port.sh @@ -0,0 +1,74 @@ +#! /bin/bash + +test_name="Port Test" + +config_file="./Tester/test3.config" +port=8080 +host="localhost" + +#paths=("/" "/test" "/test/" "/list" "list" "/wrong") # you can add many +paths=("/") # you can add many +#methods=("GET" "POST" "DELETE") +methods=("GET") +httpz=("HTTP/1.1") + + + +l1="${methods[0]} ${paths[0]} ${httpz[0]}" + +header="Host: $host" +body= + + +run_this_test() +{ + + for i in "${paths[@]}" + do + l1="${methods[0]} $i ${httpz[0]}" + request="$l1\n$header\n$body\n" + { + echo "----- $test_name -----" + echo -e "$_RED$request$_END" + } >> telnet.log + echo -e "$request" + sleep 1 + echo -e "\n" >> telnet.log + done + +} + + + +# expected result... + + +files=() + +file="expected_path_test.txt" +files+=("expected_path_test.txt") +#files+=("expected_path_root_test.txt") +#files+=("expected_path_testnoslash_test.txt") +#files+=("expected_path_testslash_test.txt") +#files+=("expected_path_list_test.txt") +#files+=("expected_path_badlist_test.txt") +#files+=("expected_path_wrong_test.txt") + + +#local_expected_test_file=$file +local_expected_test_files=() +test_path="" + +add_path() +{ + for i in "${files[@]}" + do + local_expected_test_files+=("$test_path$i") + done +} + +#add_path + + + + diff --git a/compare.txt b/compare.txt index d81fada..94ccf2a 100644 --- a/compare.txt +++ b/compare.txt @@ -1,27 +1,4 @@ telnet> Trying 127.0.0.1... -Connected to localhost. -Escape character is '^]'. -HTTP/1.1 200 OK -Server: Webserv/0.1 -Connection: keep-alive -Content-Type: text/html; charset=UTF-8 -Content-Length: 193 - - - -
-(˚3˚)
- - -HTTP/1.1 400 Bad Request -Server: Webserv/0.1 -Connection: close -Content-Type: text/html; charset=UTF-8 -Content-Length: 185 - -Le Webserv/0.1
\ No newline at end of file +telnet> ?Invalid command +telnet> ?Invalid command +telnet> telnet> telnet> \ No newline at end of file diff --git a/main_test.sh b/main_test.sh index 6cda415..63b0494 100755 --- a/main_test.sh +++ b/main_test.sh @@ -22,7 +22,8 @@ _END='\033[0m' #test_file_names=("test_template.sh" "test_header.sh" "test_path.sh") #test_file_names=("test_method.sh" "test_header.sh" "test_path.sh") -test_file_names=("test_body.sh") +test_file_names=("test_port.sh") +#test_file_names=("test_body.sh") #test_file_names=("test_valid_uri.sh") #test_file_names=("test_path.sh") diff --git a/srcs/Client.cpp b/srcs/Client.cpp index 6601908..abccc41 100644 --- a/srcs/Client.cpp +++ b/srcs/Client.cpp @@ -421,9 +421,9 @@ void Client::_parse_port_hostname(std::string host) void Client::_check_request_errors() { - // /* Debug */ std::cerr << "Content-Length=" << get_rq_headers("Content-Length") << "\n"; - // /* Debug */ std::cerr << "strtoul=" << std::strtoul(get_rq_headers("Content-Length").c_str(), NULL, 10) << "\n"; - // /* Debug */ std::cerr << "client_body_limit=" << assigned_server->client_body_limit << "\n"; + /* Debug */ std::cerr << "Content-Length=" << get_rq_headers("Content-Length") << "\n"; + /* Debug */ std::cerr << "strtoul=" << std::strtoul(get_rq_headers("Content-Length").c_str(), NULL, 10) << "\n"; + /* Debug */ std::cerr << "client_body_limit=" << assigned_server->client_body_limit << "\n"; /////////////////////// // Request line checks if (_request.method == UNKNOWN)