pulling more
This commit is contained in:
@@ -17,17 +17,19 @@ httpz=("HTTP/1.1")
|
|||||||
l1="${methods[0]} ${paths[0]} ${httpz[0]}"
|
l1="${methods[0]} ${paths[0]} ${httpz[0]}"
|
||||||
|
|
||||||
header="Host: $host\n"
|
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...
|
# turns out this does nothing...
|
||||||
#header_cycle=("Content-Length: 17" "Content-Length: 14" "Content-Length: 25")
|
#header_cycle=("Content-Length: 17\n" "Content-Length: 14" "Content-Length: 25")
|
||||||
#header_cycle=("Content-Length: 17" "")
|
#header_cycle=("Content-Length: 17\n" "\n")
|
||||||
#header_cycle=("Content-Length: 17")
|
#header_cycle=("Content-Length: 17\n")
|
||||||
#header_cycle=()
|
#header_cycle=()
|
||||||
header+="Content-Length: 15"
|
#header+="Content-Length: 8\n"
|
||||||
|
|
||||||
run_this_test()
|
run_this_test()
|
||||||
{
|
{
|
||||||
|
echo size is ${#body} >> telnet.log
|
||||||
|
|
||||||
# for i in "${header_cycle[@]}"
|
# for i in "${header_cycle[@]}"
|
||||||
for i in "${paths[@]}"
|
for i in "${paths[@]}"
|
||||||
@@ -36,7 +38,9 @@ run_this_test()
|
|||||||
l1="${methods[0]} $i ${httpz[0]}"
|
l1="${methods[0]} $i ${httpz[0]}"
|
||||||
# header_send="$header$i"
|
# header_send="$header$i"
|
||||||
header_send="$header"
|
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 "----- $test_name -----"
|
||||||
echo -e "$_RED$request$_END"
|
echo -e "$_RED$request$_END"
|
||||||
|
|||||||
23
compare.txt
23
compare.txt
@@ -1,10 +1,27 @@
|
|||||||
telnet> Trying 127.0.0.1...
|
telnet> Trying 127.0.0.1...
|
||||||
Connected to localhost.
|
Connected to localhost.
|
||||||
Escape character is '^]'.
|
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
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Le Webserv</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1 style="text-align:center">Le index (˘ ͜ʖ˘)</h1>
|
||||||
|
<hr>
|
||||||
|
<p style="text-align:center">(˚3˚)</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
HTTP/1.1 400 Bad Request
|
||||||
Server: Webserv/0.1
|
Server: Webserv/0.1
|
||||||
Connection: close
|
Connection: close
|
||||||
Content-Type: text/html; charset=UTF-8
|
Content-Type: text/html; charset=UTF-8
|
||||||
Content-Length: 197
|
Content-Length: 185
|
||||||
|
|
||||||
<!DOCTYPE html><html><head><title>413 Content Too Large</title></head><body><h1 style="text-align:center">413 Content Too Large</h1><hr><p style="text-align:center">Le Webserv/0.1</p></body></html>
|
<!DOCTYPE html><html><head><title>400 Bad Request</title></head><body><h1 style="text-align:center">400 Bad Request</h1><hr><p style="text-align:center">Le Webserv/0.1</p></body></html>
|
||||||
@@ -42,8 +42,19 @@ server {
|
|||||||
|
|
||||||
location /upload {
|
location /upload {
|
||||||
allow_methods POST;
|
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;
|
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
|
# root doesn’t matter if used only with POST and no CGI
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,10 +95,12 @@ server {
|
|||||||
location /test/test_deeper/ {
|
location /test/test_deeper/ {
|
||||||
# allow_methods
|
# allow_methods
|
||||||
root ./www/test/test_deeper/;
|
root ./www/test/test_deeper/;
|
||||||
|
index index1.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /test/test_deeper/super_deep {
|
location /test/test_deeper/super_deep {
|
||||||
root ./www/test/test_deeper/super_deep/;
|
root ./www/test/test_deeper/super_deep/;
|
||||||
|
index something.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
# location /test/test_deeper/something.html {
|
# location /test/test_deeper/something.html {
|
||||||
|
|||||||
@@ -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))
|
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)
|
if (get_rq_headers("Content-Type").find("multipart/form-data") != NPOS)
|
||||||
_parse_multipart_body(pos);
|
_parse_multipart_body(pos);
|
||||||
else
|
else
|
||||||
_request.body = raw_request.substr(pos + CRLF_SIZE*2);
|
_request.body = raw_request.substr(pos + CRLF_SIZE*2);
|
||||||
body_complete = true;
|
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";
|
std::cerr << "Content-Length = " << std::strtoul(get_rq_headers("Content-Length").c_str(), NULL, 10) << "\n";
|
||||||
// _request.body = raw_request.substr(pos);
|
std::cerr << "raw_request.size() - pos = " << raw_request.size() - pos << "\n";
|
||||||
// std::cerr << "_request.body.size() = " << _request.body.size() << "\n";
|
_request.body = raw_request.substr(pos);
|
||||||
|
std::cerr << "_request.body.size() = " << _request.body.size() << "\n";
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
// Body checks
|
// 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";
|
std::cerr << "err _parse_first_line(): wrong number of elements (" << line.size() << " instead of 3)\n";
|
||||||
status = 400; // "bad request"
|
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
|
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;
|
std::string uri = path;
|
||||||
if (uri[uri.size() - 1] == '/' && uri.size() != 1)
|
if (uri[uri.size() - 1] == '/' && uri.size() != 1)
|
||||||
uri.erase(uri.size() - 1);
|
uri.erase(uri.size() - 1);
|
||||||
|
|||||||
2
srcs/cgi-bin/upload_file.php
Normal file → Executable file
2
srcs/cgi-bin/upload_file.php
Normal file → Executable file
@@ -10,7 +10,7 @@
|
|||||||
# echo("File was uploaded successfully!");
|
# echo("File was uploaded successfully!");
|
||||||
|
|
||||||
// this part needs to be grabed from POST uri
|
// 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 = $_POST["upload_dir"];
|
||||||
//$target_dir = $_GET["upload_dir"];
|
//$target_dir = $_GET["upload_dir"];
|
||||||
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
|
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
|
||||||
|
|||||||
@@ -55,8 +55,11 @@ int Webserv::_read_request(Client *client)
|
|||||||
|
|
||||||
// print_special(client->raw_request);
|
// print_special(client->raw_request);
|
||||||
|
|
||||||
|
std::cerr << "client header complete: " << client->header_complete << "\n"; // DEBUG
|
||||||
|
|
||||||
if (!client->header_complete)
|
if (!client->header_complete)
|
||||||
{
|
{
|
||||||
|
std::cout << "Header not complete\n"; // debug
|
||||||
client->parse_request_headers(_servers);
|
client->parse_request_headers(_servers);
|
||||||
if (client->status)
|
if (client->status)
|
||||||
return READ_COMPLETE;
|
return READ_COMPLETE;
|
||||||
@@ -75,6 +78,7 @@ int Webserv::_read_request(Client *client)
|
|||||||
}
|
}
|
||||||
if (client->header_complete)
|
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->read_body_size += ret; // Not accurate, part of body could have been read with headers, unused for now
|
||||||
client->parse_request_body();
|
client->parse_request_body();
|
||||||
if (client->status || client->body_complete)
|
if (client->status || client->body_complete)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<hr>
|
<hr>
|
||||||
<p style="text-align:center">Time to submit something:</p>
|
<p style="text-align:center">Time to submit something:</p>
|
||||||
<!-- <form action="./srcs/cgi-bin/upload_file.php" method="post" enctype="multipart/form-data"> -->
|
<!-- <form action="./srcs/cgi-bin/upload_file.php" method="post" enctype="multipart/form-data"> -->
|
||||||
<form action="/uploaded" method="post" enctype="multipart/form-data">
|
<form action="/cgi-bin/upload_file.php" method="post" enctype="multipart/form-data">
|
||||||
<!-- <input type="hidden" name="upload_dir" value="./www/uploaded/"> -->
|
<!-- <input type="hidden" name="upload_dir" value="./www/uploaded/"> -->
|
||||||
<input type="file" id="fileToUpload" name="myFile">
|
<input type="file" id="fileToUpload" name="myFile">
|
||||||
<input type="submit" value="Upload File">
|
<input type="submit" value="Upload File">
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
https://www.rfc-editor.org/rfc/rfc9110#name-multipart-types
|
https://www.rfc-editor.org/rfc/rfc9110#name-multipart-types
|
||||||
https://www.rfc-editor.org/rfc/rfc2046#section-5.1.1
|
https://www.rfc-editor.org/rfc/rfc2046#section-5.1.1
|
||||||
-->
|
-->
|
||||||
<form action="/upload" method="post" enctype="multipart/form-data">
|
<form action="/cgi-bin/upload_file.php" method="post" enctype="multipart/form-data">
|
||||||
<input type="file" name="upload_file1">
|
<input type="file" name="upload_file1">
|
||||||
<input type="submit">
|
<input type="submit">
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user