Skip to content

Commit

Permalink
[Location] Not found for location undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
unkn0wn107 committed Jun 25, 2024
1 parent ea23e3a commit 80b4cab
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/VirtualServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: agaley <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/24 15:10:25 by mchenava #+# #+# */
/* Updated: 2024/06/24 16:21:51 by agaley ### ########lyon.fr */
/* Updated: 2024/06/25 17:00:41 by agaley ### ########lyon.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -74,23 +74,25 @@ LocationConfig& VirtualServer::getLocationConfig(const std::string& uri) {
}

HTTPResponse* VirtualServer::checkRequest(HTTPRequest& request) {
std::string protocol = request.getProtocol();
std::string method = request.getMethod();
std::string uri = request.getURI();
std::string body = request.getBody();
int contentLength = request.getContentLength();
LocationConfig location = getLocationConfig(uri);
std::string protocol = request.getProtocol();
std::string method = request.getMethod();
std::string uri = request.getURI();
std::string body = request.getBody();
int contentLength = request.getContentLength();

LocationConfig location;
try {
location = getLocationConfig(uri);
} catch (const std::exception& e) {
_log.error("Location not found for URI: " + uri);
return new HTTPResponse(HTTPResponse::NOT_FOUND, location.error_pages);
}

if (protocol != "HTTP/1.1") {
_log.error("Unsupported protocol");
return new HTTPResponse(HTTPResponse::BAD_REQUEST, location.error_pages);
}

if (location.location.empty()) {
_log.error("Location not found for URI: " + uri);
return new HTTPResponse(HTTPResponse::NOT_FOUND, location.error_pages);
}

if (std::find(location.allowed_methods.begin(),
location.allowed_methods.end(),
method) == location.allowed_methods.end()) {
Expand Down

0 comments on commit 80b4cab

Please sign in to comment.