Skip to content

Commit

Permalink
fixing thing before the real end???
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-philippe Martel committed Oct 7, 2022
1 parent e24b997 commit a011c50
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ clean:
${RM} ${OBJS}

test: all
./${NAME} & sleep 1 && http :9991

./test.sh
fclean: clean
@${RM} ${NAME}
@${RM} ${NAME_TEST}
Expand Down
1 change: 1 addition & 0 deletions Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ void server::get_data_from_client(int i)
}
serveInfo.locations[page.second].len = content_length;
resp = response(serveInfo.locations[page.second],this->serveInfo.error_pages, data);

}
}
}
Expand Down
7 changes: 7 additions & 0 deletions response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ response::response(location_info local_info, std::map<int, std::string> error_pa
this->status = "301 Moved Permanently";
this->status_code = 301;
}
else if (local_info.index == "")
{
this->status = "403 Forbidden";
this->status_code = 403;
}
else if (local_info.root == "")
{
this->status = "404 Not Found";
Expand Down Expand Up @@ -277,6 +282,7 @@ void response::set_response(int status_code)
{
this->status_code = status_code;
this->status = "200 OK";

}
else if(status_code > 400 && status_code < 500)
{
Expand All @@ -290,6 +296,7 @@ void response::set_response(int status_code)
}
else
{

this->status_code = status_code;
status = "200 OK";
}
Expand Down
55 changes: 55 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#start server on port 8081
./webserv &
#try to ping localhost on port 8081
#send a POST request to localhost on port 8081 with a header of content-length: 0
echo "Posting to localhost:8081 with a body size of 0\n\n "
sleep 1
nl -ba -w10 -s" " /dev/zero | head -c 0 | curl -v -X POST -H "Content-Length: 0" http://localhost:8081
sleep 1
echo "-----------------------------------------------\n\n "

echo "Posting to localhost:8081 with a body size too big"
#send a POST request to localhost on port 8081 with a header of lenght too big to be handled by the server
nl -ba -w10 -s" " /dev/zero | head -c 0 | curl -v -X POST -H "Content-Length: 8888888888888888888888888888" http://localhost:8081
sleep 1
echo "-----------------------------------------------\n\n"


echo "GET request on a wrong path"
nl -ba -w10 -s" " /dev/zero | head -c 0 | curl -v -X GET http://localhost:8081/rat
sleep 1
echo "-----------------------------------------------\n\n"

echo "Posting to localhost:8081 with incorrect request option"
#send a POST request to localhost on port 8081 with a header of lenght too big to be handled by the server
nl -ba -w10 -s" " /dev/zero | head -c 0 | curl -v -X SHIT http://localhost:8081

sleep 1
echo "-----------------------------------------------\n\n"
echo "GET request to localhost:8081 to show directory listing"
#send a POST request to localhost on port 8081 with a header of lenght too big to be handled by the server
nl -ba -w10 -s" " /dev/zero | head -c 20 | curl -v -X GET http://localhost:8081/upload

sleep 1
echo "-----------------------------------------------\n\n"

echo "DELETE to localhost:8081"
find ./resources | grep upload
nl -ba -w10 -s" " /dev/zero | head -c 20 | curl -v -X DELETE http://localhost:8081/
find ./resources | grep upload
sleep 1
echo "-----------------------------------------------\n\n"


echo "GET request on another instance of the server"
find ./resources | grep upload
nl -ba -w10 -s" " /dev/zero | head -c 20 | curl -v -X GET http://localhost:8082/
sleep 1
echo "-----------------------------------------------\n\n"




#kill the server
kill %1

0 comments on commit a011c50

Please sign in to comment.