Skip to content

Commit

Permalink
Fix DELETE
Browse files Browse the repository at this point in the history
  • Loading branch information
unkn0wn107 committed Aug 27, 2024
1 parent e097a6f commit c5dbb46
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/ConnectionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: agaley <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 16:11:21 by agaley #+# #+# */
/* Updated: 2024/07/10 13:29:04 by agaley ### ########lyon.fr */
/* Updated: 2024/08/27 17:20:41 by agaley ### ########lyon.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -127,7 +127,7 @@ void ConnectionHandler::_receiveRequest(struct epoll_event& event) {
}

if (headersEnd){
if (_request->getMethod() == "GET" || _request->getMethod() == "HEAD")
if (_request->getMethod() == "GET" || _request->getMethod() == "HEAD" || _request->getMethod() == "DELETE")
_processRequest(event);
else if (!contentLengthFound) {
HTTPResponse::sendResponse(HTTPResponse::LENGTH_REQUIRED, _clientSocket);
Expand Down
1 change: 1 addition & 0 deletions src/HTTPMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ HTTPResponse* HTTPMethods::_handleDeleteRequest(HTTPRequest& request) {
response->addHeader("Content-Type", "text/html");
response->addHeader("Content-Length", Utils::to_string(path.size() + 66));
response->setBody("<html><body>File deleted.</body></html>");
response->addHeader("Content-Length", "39");
return response;
} else {
if (errno == ENOENT) {
Expand Down
2 changes: 1 addition & 1 deletion src/VirtualServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ HTTPResponse* VirtualServer::checkRequest(HTTPRequest& request) {
return new HTTPResponse(HTTPResponse::METHOD_NOT_ALLOWED, location);
}

if (method != "GET" && method != "HEAD") {
if (method != "GET" && method != "HEAD" && method != "DELETE") {
if (!body.empty() && contentLength == -1) {
_log.warning("CheckRequest: Content length not provided");
return new HTTPResponse(HTTPResponse::LENGTH_REQUIRED, location);
Expand Down

0 comments on commit c5dbb46

Please sign in to comment.