diff --git a/Tester/test_body.sh b/Tester/test_body.sh index 63c4bde..4754772 100644 --- a/Tester/test_body.sh +++ b/Tester/test_body.sh @@ -17,17 +17,19 @@ httpz=("HTTP/1.1") l1="${methods[0]} ${paths[0]} ${httpz[0]}" header="Host: $host\n" -body="this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message \n" +body="this is a message \n" +body+="this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message this is a message \n" # turns out this does nothing... -#header_cycle=("Content-Length: 17" "Content-Length: 14" "Content-Length: 25") -#header_cycle=("Content-Length: 17" "") -#header_cycle=("Content-Length: 17") +#header_cycle=("Content-Length: 17\n" "Content-Length: 14" "Content-Length: 25") +#header_cycle=("Content-Length: 17\n" "\n") +#header_cycle=("Content-Length: 17\n") #header_cycle=() -header+="Content-Length: 15" +#header+="Content-Length: 8\n" run_this_test() { + echo size is ${#body} >> telnet.log # for i in "${header_cycle[@]}" for i in "${paths[@]}" @@ -36,7 +38,9 @@ run_this_test() l1="${methods[0]} $i ${httpz[0]}" # header_send="$header$i" header_send="$header" - request="$l1\n$header_send\n\n$body\n" + ## if you add an extra \n after header send you get a status code 200 OK and 400 bad request, but like both + # request="$l1\n$header_send\n$body\n" + request="$l1\n$header_send\n$body" { echo "----- $test_name -----" echo -e "$_RED$request$_END" diff --git a/compare.txt b/compare.txt index 689022d..d81fada 100644 --- a/compare.txt +++ b/compare.txt @@ -1,10 +1,27 @@ telnet> Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. -HTTP/1.1 413 Content Too Large +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: 197 +Content-Length: 185 -Le Webserv/0.1
\ No newline at end of file +Le Webserv/0.1
\ No newline at end of file diff --git a/default.config b/default.config index 329a127..033bc4a 100644 --- a/default.config +++ b/default.config @@ -42,8 +42,19 @@ server { location /upload { allow_methods POST; + # autoindex on; + # root ./www/; + # index upload_form_single.html; + + # upload_dir ./www/user_files/; + # root doesn’t matter if used only with POST and no CGI + } + + location /uploaded { + allow_methods GET; autoindex on; - upload_dir ./www/user_files/; + # upload_dir ./www/user_files/; + root ./www/user_files; # root doesn’t matter if used only with POST and no CGI } @@ -84,10 +95,12 @@ server { location /test/test_deeper/ { # allow_methods root ./www/test/test_deeper/; + index index1.html; } location /test/test_deeper/super_deep { root ./www/test/test_deeper/super_deep/; + index something.html; } # location /test/test_deeper/something.html { diff --git a/srcs/Client.cpp b/srcs/Client.cpp index 5ca4816..6601908 100644 --- a/srcs/Client.cpp +++ b/srcs/Client.cpp @@ -137,16 +137,18 @@ void Client::parse_request_body() } else if (raw_request.size() - pos >= std::strtoul(get_rq_headers("Content-Length").c_str(), NULL, 10)) { + std::cerr << "Content-Length = " << std::strtoul(get_rq_headers("Content-Length").c_str(), NULL, 10) << "\n"; if (get_rq_headers("Content-Type").find("multipart/form-data") != NPOS) _parse_multipart_body(pos); else _request.body = raw_request.substr(pos + CRLF_SIZE*2); body_complete = true; } - // std::cerr << "Content-Length = " << std::strtoul(get_rq_headers("Content-Length").c_str(), NULL, 10) << "\n"; - // std::cerr << "raw_request.size() - pos = " << raw_request.size() - pos << "\n"; - // _request.body = raw_request.substr(pos); - // std::cerr << "_request.body.size() = " << _request.body.size() << "\n"; + + std::cerr << "Content-Length = " << std::strtoul(get_rq_headers("Content-Length").c_str(), NULL, 10) << "\n"; + std::cerr << "raw_request.size() - pos = " << raw_request.size() - pos << "\n"; + _request.body = raw_request.substr(pos); + std::cerr << "_request.body.size() = " << _request.body.size() << "\n"; /////////////// // Body checks @@ -344,6 +346,7 @@ void Client::_parse_request_line() { std::cerr << "err _parse_first_line(): wrong number of elements (" << line.size() << " instead of 3)\n"; status = 400; // "bad request" + // if the header is fucked up, then this will be triggered, but for some reason in test_body.sh case another response 200 OK is sent first? } else { @@ -512,6 +515,7 @@ If we get a url that ends in / ignore the last / */ +// TODO: technically i think this is useless... std::string uri = path; if (uri[uri.size() - 1] == '/' && uri.size() != 1) uri.erase(uri.size() - 1); diff --git a/srcs/cgi-bin/upload_file.php b/srcs/cgi-bin/upload_file.php old mode 100644 new mode 100755 index 251aefb..572f5be --- a/srcs/cgi-bin/upload_file.php +++ b/srcs/cgi-bin/upload_file.php @@ -10,7 +10,7 @@ # echo("File was uploaded successfully!"); // this part needs to be grabed from POST uri -$target_dir = "./www/uploaded/"; +$target_dir = "./www/user_files/"; //$target_dir = $_POST["upload_dir"]; //$target_dir = $_GET["upload_dir"]; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); diff --git a/srcs/webserv/request.cpp b/srcs/webserv/request.cpp index 713de12..54e90a6 100644 --- a/srcs/webserv/request.cpp +++ b/srcs/webserv/request.cpp @@ -55,8 +55,11 @@ int Webserv::_read_request(Client *client) // print_special(client->raw_request); + std::cerr << "client header complete: " << client->header_complete << "\n"; // DEBUG + if (!client->header_complete) { + std::cout << "Header not complete\n"; // debug client->parse_request_headers(_servers); if (client->status) return READ_COMPLETE; @@ -75,6 +78,7 @@ int Webserv::_read_request(Client *client) } if (client->header_complete) { + std::cerr << "Client header Complete\n"; // client->read_body_size += ret; // Not accurate, part of body could have been read with headers, unused for now client->parse_request_body(); if (client->status || client->body_complete) diff --git a/www/test/submit_form.html b/www/test/submit_form.html index c4d556b..7922e67 100644 --- a/www/test/submit_form.html +++ b/www/test/submit_form.html @@ -8,7 +8,7 @@Time to submit something:
-